home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor2 / math9.txt < prev    next >
Text File  |  1995-03-31  |  111KB  |  3,344 lines

  1. DOC 1.1 -- MATH directory documentation 
  2. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  3. NOTE!  This is a plain ASCII text file containing multiple 
  4. documents. You may find it most convenient to view or print this file 
  5. by running the DOC.EXE program (supplied on this disk) on your PC. 
  6. This is the first Goodies Disk to do it this way.  Hope you like it. 
  7. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  8. :GD9 
  9. :Mathematical Goodies 
  10. :-jkh- 
  11. @@AREA       SG 
  12. (Comp.sys.hp48) 
  13. Item: 2753 by an6602@anon.penet.fi [Dewayne Cushman] 
  14. Subj: AREA: calculates the area of a polygon with known 
  15.       coordinates. 
  16. Date: 28 Jan 1993 
  17.  
  18. Six programs are in the AREA directory. These are used 
  19. to find the area of any polygon. 
  20.  
  21. When extracted the dir AREA contains 6 programs: 
  22.  
  23. 1.  AREA - main program 
  24.  
  25. 2.  ####### - degree symbols for neatness 
  26.  
  27. 3.  LST - The last matrix that was entered 
  28.  
  29. 4.  ###### - degree symbols for neatness 
  30.  
  31. 5.  ##### - degree symbols for neatness 
  32.  
  33. 6.  HELP - Hit HELP for instruction (just enter the 
  34.     matrix (use MATRIX on HP is handy) and store in the 
  35.     LST variable (LS+LST). Hit enter a 2nd time to see 
  36.     more help. Then hit AREA to get the area or just hit 
  37.     AREA with the matrix on the stack. 
  38.  
  39.     e.g. 
  40.     For 0 0 0 10 10 10 10 0    -- 2 by n+1 matrix 
  41.                                (depends on the polygon) 
  42.                                this is a 10x10 box [[0 0] 
  43.                                [0 10] [10 10] [10 0] [0 
  44.                                0]]. NOTE: the first 
  45.                                point is repeated. 
  46.  
  47.     1:            100          -- In square feet if that 
  48.                                is the units you used. 
  49.  
  50. BIO - Dewayne Cushman wrote this program(s). 
  51.  
  52.       We are both CE students at OU. Ken will graduate 
  53.       in Spr.'93. 
  54.  
  55. These programs are what I (Kenneth Hobson) use in my work 
  56. for the OKlahoma Department of Transportation (County 
  57. Bridge - Norman). They would have been nice to have had 
  58. when I took SURVEY and other math courses. 
  59.  
  60. Moidify anything you like as I wrote these and posted 
  61. them for all to enjoy. 
  62.  
  63. Regards,  Kenneth Hobson 
  64. internet  at 
  65. krhobson@midway.ecn.uoknor.edu 
  66.  
  67. And some local BBS's such as protoboard bbs 405-275-6827 
  68. @@CHEBY      SG 
  69. Chebychev Polynomial Coefficients, by Ron Zukerman 
  70. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  71. for HP 48 S/SX/G/GX 
  72.  
  73. (Comp.sys.hp48) 
  74. Item: 2303 by Fallonjb95%cs14@cadetmail.usafa.af.mil 
  75.               [Joshua B. L. Fallon] 
  76. Subj: need help with algorythm 
  77. Date: 21 Oct 1993 
  78.  
  79. I only recently got my HP48gx, and am confused on how to 
  80. code this algorythm that I have.  What I need to do, is 
  81. use this to determine Chebyshev polynomials. Then, take 
  82. the polynomial and put it into the standard polynomial 
  83. 'list' form. (ie. {1 4 6 4 1}). I would have it in that 
  84. form to make it easier to change it to a transfer 
  85. function.( for EE). Any help at all would be a big help. 
  86. I need to be able to get only the nth polynomial. 
  87.  
  88. C0(w) = 1 
  89.   
  90. C1(w) = w 
  91. C  (w) = 2w*C (w) - C   (w) 
  92.  n+1         n       n-1 
  93.  
  94. Thanks in advance for any help. 
  95. ****************************************** 
  96. *      `` `                -----         * 
  97. *  -= RAINMAN =-             |           * 
  98. *            Blue         \ / \  /       * 
  99. *              Skies...     \  /         * 
  100. * FALLONJB95%CS14@CADETMAIL.USAFA.AF.MIL * 
  101. ****************************************** 
  102.  
  103. ---------- 
  104. Resp: 1 of 1 by ronzu@comm.mot.com [Ron Zuckerman] 
  105. Date: 21 Oct 1993 
  106.  
  107. I only have a HP48SX, so I don't know what a standard 
  108. polynomial list form is supposed to look like. However, 
  109. here is a program to calculate the coefficients of a 
  110. Chebyshev polynomial: 
  111.  
  112. << -> N 
  113.     << [ 1 ] 
  114.        IF N 0 > THEN [ 0 1 ] 
  115.            IF N 1 > THEN 
  116.                3 N 1 + FOR I 
  117.                    0 OVER OBJ-> DROP I ->ARRY 2 * 3 PICK 
  118.                    OBJ-> DROP 0 0 I ->ARRY - ROT DROP 
  119.                NEXT 
  120.            END 
  121.            SWAP DROP 
  122.        END 
  123.        OBJ-> OBJ-> DROP ->LIST 
  124.     >> 
  125. >> 
  126.  
  127. To use the program just put the value of N on the stack 
  128. and run this program. The results are returned in a list 
  129. whose structure is as follows: 
  130.  
  131. { c0 c1 c2 ... cN } 
  132.  
  133. where: Cn(w) = c0 + c1*w + c2*w^2 + ... + cN*w^N 
  134.  
  135. Ron Zuckerman, KA4RPD  E-mail: ronzu@isp.csg.mot.com 
  136. Phone: (708)523-7805   FAX: (708)523-7847 
  137. @@CUFIT      SG 
  138. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  139. Subj: Polynomial Curvefit 
  140. Author: Joe Muccillo 
  141. Date: 24 Sept. 1993 
  142. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  143.  
  144. [Requires the MATRIX library. -jkh-] 
  145.  
  146. [Note: This is a statistical "best fit" program, not 
  147.  necessarily a mathematically exact fit. For 
  148.  mathematical work, see PFIT. -jkh-] 
  149.  
  150. From the looks of some of the programs on the Goodies 
  151. disks it would appear that just about everyone has had a 
  152. go at writing one of these programs. Here is my attempt 
  153. which may be of some use. 
  154.  
  155. Load the CUFIT subdirectory onto your HP48. The two 
  156. program files are "FIT" and "PLOT". The remaining 
  157. variables are either input or output variables. A 
  158. description of each of the files or variables is given 
  159. below. As with most of my programs you will need a copy 
  160. of my matrix utilities library, to be found somewhere on 
  161. this disk, in order to run it. 
  162.       
  163.      FIT - Fits a polynomial of specified order to the X 
  164.            Y data contained in the statistics data 
  165.            matrix, "SumDAT". The program is interactive. 
  166.            All you have to do is run the program and 
  167.            enter the degree of polynomial when prompted. 
  168.            Of course, the degree of the polynomial must 
  169.            be less than N-1, where N is the number of 
  170.            data points. On successful completion the 
  171.            program stores information into the "COEF", 
  172.            "YNEW" and "RESI" variables. 
  173.  
  174.    PLOT  - Performs the following functions: 
  175.  
  176.                = Takes the matrix of coefficients from 
  177.                  the "COEF" variable and forms the 
  178.                  equation of the polynomial, storing it 
  179.                  in the "EQ" variable. 
  180.  
  181.                = Draws a scatter plot of the data 
  182.                  contained in the "SumDAT" matrix. 
  183.  
  184.                = Superimposes on the scatter plot a plot 
  185.                  of the polynomial contained in the "EQ" 
  186.                  variable. 
  187.  
  188.     COEF - Contains a one column matrix containing the 
  189.            coefficients of the polynomial starting with 
  190.            the constant term in the first row and the 
  191.            coefficient of X^(N-1) in the final row. 
  192.  
  193.     YNEW - Contains the new values of the dependent 
  194.            variable, Y from the polynomial curve 
  195.            corresponding to the values of the independent 
  196.            variable, X in the "SumDAT" variable. 
  197.  
  198.     RESI - Contains the resultant residuals, ie the 
  199.            difference between the new and old Y values. 
  200.  
  201.  
  202. Successful execution of the FIT program also leaves one 
  203. number on the stack. This value, tagged "SUMSQ", is the 
  204. sum of the square of the resultant residuals and has been 
  205. included to give some idea of how well the polynomial of 
  206. specified degree fits the data. On its own this value 
  207. doesn't mean much but it is useful in comparing how well 
  208. polynomials of varying degrees fit the given data. 
  209. Running the plot program is also useful in seeing how 
  210. good the fit is. 
  211.  
  212. I have noticed one problem with the program which I 
  213. haven't been able to resolve. When fitting polynomials 
  214. of high degree to several data points the "SUMSQ" 
  215. quantity actually increases with increasing degree of 
  216. polynomial. The plot also shows that the polynomial 
  217. curve does not fit the data very well. I initially 
  218. attributed this to numerical problems resulting from 
  219. insufficient significant figures used in calculations 
  220. particularly when high degree polynomials are used. Has 
  221. anyone else had this problem and if so has anyone been 
  222. able to solved it. 
  223.  
  224.  
  225. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  226. Joe Muccillo 
  227. 66 Prospect St  
  228. Pascoe Vale, 3044 
  229. Melbourne 
  230. AUSTRALIA 
  231. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  232. @@ERRF       SG 
  233. (Comp.sys.hp48) 
  234. Item: 56 by vsteiger@ubeclu.unibe.ch [Rudolf von Steiger] 
  235. Subj: Erf, Erfc 
  236. Date: 22 Feb 1993 
  237.  
  238. Erf and erfc can be written as 
  239.  
  240.    (r) -> x (r) 1 0 .5 x UTPN 2 * - ─ ─ 
  241.    'ERF' STO 
  242.  
  243.    (r) -> x (r) 0 .5 x UTPN 2 * ─ ─ 
  244.    'ERFC' STO 
  245.  
  246.         ruedi 
  247. ííííííííííííííííííííííííííííííííííííííííííííííííííííííííí 
  248. Dr. Rudolf von Steiger, Physikalisches Institut, 
  249. University of Bern, 
  250. Sidlerstrasse 5, 3012 Bern (Switzerland)  
  251. Phone: ++41 (0)31 65 44 19; Fax: ++41 (0)31 65 44 05 
  252. RFC: vsteiger@phim.unibe.ch   
  253. X.400: S=vsteiger;OU=phim;O=unibe;P=switch;a=arcom;c=ch 
  254. HEPNET/SPAN: 20579::49203::vsteiger 
  255. DECnet (Switzerland): 49203::vsteiger 
  256. ********************************************************* 
  257. @@GEOMETRY   SG 
  258. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  259. Subj: Geometry programs 
  260. Author: Joe Muccillo 
  261. Date: 23 Sept 1993 
  262. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  263.  
  264.  
  265. Here is a compilation of geometry programs which I have 
  266. placed in a library labelled ( 801: GEOMETRY ). I have 
  267. found a great number of uses for SIMPS, AG and IBOX in 
  268. surveying and engineering applications and would be 
  269. interested to know whether anyone else can find some 
  270. other interesting uses for them. Please note that none 
  271. of these programs are guaranteed in any way against 
  272. defect so use them at your own risk. 
  273.  
  274.  
  275. TRIA - TRIANGULAR GEOMETRY ANALYSIS 
  276.  
  277. SIMPS - AREA CALCULATION USING SIMPSON'S RULE 
  278.  
  279. AG - AREA CALCULATION USING TRAPEZOID RULE 
  280.  
  281. IBOX - GENERAL AREA PROPERTY ANALYSIS 
  282.  
  283. ISEG - AREA PROPERTIES FOR CIRCULAR SEGMENT 
  284.  
  285. VSEG - VOLUME ENCLOSED BY CIRCULAR SEGMENT AND 
  286.        SLOPING PLANE 
  287.  
  288. VCON - VOLUME OF A CONE 
  289.  
  290. VSPH - VOLUME OF A SPHERE 
  291.  
  292. SCON - SURFACE AREA OF A CONE 
  293.  
  294. SSPH - SURFACE AREA OF A SPHERE                               
  295.  
  296. CINT - CIRCLE INSCRIBED IN TRIANGLE 
  297.  
  298. INVER - SUBROUTINE USED WITH IBOX 
  299.  
  300. EQ1,EQ2,EQ3 - SUBROUTINES USED WITH TRIA 
  301.  
  302.  
  303.  
  304.  
  305. TRIA - TRIANGULAR GEOMETRY ANALYSIS 
  306.  
  307. INPUT 
  308.  
  309. "TRIA" is a program used to evaluate side lengths, angles 
  310. and the enclosed area of a triangle given certain 
  311. information. The information required in order to 
  312. successfully run the program can be any of the following: 
  313.  
  314. - 3 side lengths, zero angles. 
  315. - 2 side lengths, 1 angle. 
  316. - 1 side length, 2 angles. 
  317.  
  318. When run the program prompts:  
  319.  
  320.              "ENTER A B C à á ë 
  321.              (0 IF UNDEFINED)" 
  322.  
  323. Where A:       Side length A 
  324.       B:       Side length B 
  325.       C:       Side length C 
  326.       [alpha]: Angle at intersection of sides B and C 
  327.       [beta]:  Angle at intersection of sides A and C  
  328.       [delta]: Angle at intersection of sides A and B 
  329.  
  330. Enter 0 for the items you wish the program to evaluate or 
  331. which are undefined ensuring that the input requirements 
  332. listed above are satisfied. The program will evaluate 
  333. all undefined items in addition to the area enclosed by 
  334. the triangle. 
  335.  
  336. Note:  Avoid entering redundant information at the prompt 
  337. as this may lead to unsuccessful or incorrect program 
  338. execution. The above list shows the minimum information 
  339. required to uniquely define the geometry of the triangle. 
  340. Any additional information is redundant and should be 
  341. omitted. 
  342.  
  343.  
  344. OUTPUT 
  345.  
  346. A single output screen is obtained listing all quantities 
  347. A, B, C, [alpha], [beta], [delta] and the AREA. 
  348.  
  349.  
  350. USING "TRIA" WITH QUADRILATERALS 
  351.  
  352. It is possible to indirectly apply "TRIA" to obtain 
  353. solutions for the area and internal angles of 
  354. quadrilaterals. The minimum required information in 
  355. order to uniquely define a quadrilateral is the lengths 
  356. of all sides in addition to 1 internal angle. The 
  357. procedure for evaluating the area bounded by the 
  358. quadrilateral and the remaining internal angles is 
  359. described below. 
  360.  
  361. 1. Divide the quadrilateral into 2 triangles with the 
  362.    single defined angle forming the apex of one of the 
  363.    triangles and the diagonal dividing the 2 triangles. 
  364.  
  365. 2. Using the known side lengths and defined angle 
  366.    evaluate the area of triangle No. 1 and the length of 
  367.    the diagonal using the "TRIA" program. This step also 
  368.    evaluates the part of the internal angles of the 
  369.    quadrilateral associated with triangle No. 1. 
  370.  
  371. 3. With the diagonal length having been evaluated, and 
  372.    using the remaining side lengths, evaluate the area 
  373.    and associated internal angles of triangle No. 2 using 
  374.    the "TRIA" program. 
  375.   
  376. 4. Add the two areas together to obtain the total area of 
  377.    the quadrilateral and add the internal angles of each 
  378.    triangle, where appropriate, to evaluate the internal 
  379.    angles of the quadrilateral. 
  380.  
  381.     
  382. SIMPS - AREA CALCULATION USING SIMPSON'S RULE 
  383.  
  384. The program "SIMPS" evaluates the area of a set of N data 
  385. points using Simpson's Rule. In addition to the area the 
  386. program also calculates the horizontal centroid of the 
  387. data. The data is entered into a single column matrix 
  388. containing the vertical ordinates of the equally spaced 
  389. data points. There must be an ODD number of EQUALLY 
  390. SPACED points for Simpson's Rule to apply. This matrix 
  391. is placed in level 2 of the stack and the equal 
  392. horizontal spacing in level 1. 
  393.  
  394. The output consists of two numbers: 
  395.  
  396.      - The Area in stack level 2 
  397.      - The X centroid of area measured from the first 
  398.        data point in the input matrix assuming this point 
  399.        has an X value of zero. 
  400.  
  401.  
  402. Using Simpson's Rule the area of a set of N data points 
  403. is given by the following formula where N is odd and the 
  404. horizontal spacing, h, between points is equal. 
  405.  
  406.  
  407.      Area = (y1+4*y2+2*y3+2*y4+2*y5+....+4*yN-1+yN)*h/3 
  408.  
  409.  
  410. AG - AREA CALCULATION USING TRAPEZOID RULE 
  411.  
  412. The program "AG" evaluates the area below a curve defined 
  413. by a set of X Y data points assuming the individual data 
  414. points are joined by a straight line. This is a 
  415. variation on the trapezoid rule which permits the X 
  416. spacing between data points to vary. The X Y coordinates 
  417. of the points are entered into a two column array with 
  418. the X values in the first column and Y values in the 
  419. second. The X values must be in ascending order. In 
  420. addition to the area the program also calculates the 
  421. horizontal centroid of the data and the overall range of 
  422. the data points specified. The matrix of coordinates is 
  423. entered into level 1 of the stack. 
  424.  
  425. The output consists of two numbers: 
  426.  
  427.      - The Area in stack level 2 
  428.      - The X centroid of area 
  429.      - The range of data in the input matrix 
  430.            = Xn - X1 
  431.  
  432.  
  433.  
  434.  
  435. IBOX - GENERAL AREA PROPERTY ANALYSIS 
  436.  
  437. This program will calculate the area "A", second moments 
  438. of area "Ixx" and "Iyy", the product of area "Ixy" and 
  439. the centroid "x" and "y" for an arbitrary shape. Areas 
  440. containing voids can also be handled. The analysis 
  441. method is based on contour integration principles. 
  442. Although this program can be used in a variety of 
  443. applications I originally developed it as a cross section 
  444. property analysis program for use in structural 
  445. engineering. For example, it can be used to assess the 
  446. section properties of a multi celled box girder. 
  447.  
  448. The analysis method involves firstly establishing an 
  449. arbitrary and convenient coordinate axis system from 
  450. which coordinates of points around the area are 
  451. referenced. Labelling of coordinates proceeds using the 
  452. following criteria: 
  453.  
  454.      - Coordinates are labelled in a clockwise fashion 
  455.        around the perimeter of the area and anticlockwise 
  456.        within a void. 
  457.  
  458.      - A coordinate should be defined at the end of each 
  459.        straight line segment. 
  460.  
  461.      - Where curved geometries are being analysed the 
  462.        curve is divided into a series of straight line 
  463.        segments with nodes at each end. The more 
  464.        straight line segments are defined the more 
  465.        accurate are the results. Note that a geometry 
  466.        consisting of straight line segments only will 
  467.        produce exact results. 
  468.  
  469.      - The final coordinate should be equal to the first 
  470.        coordinate so as to produce a closed section. 
  471.        Note that this rule can be waived when the y value 
  472.        of the last coordinate is the same as that of the 
  473.        first. 
  474.  
  475. Data is entered into a two column array with x and y 
  476. coordinates of successive points stored in the first and 
  477. second columns respectively. This array is then placed 
  478. in level 1 of the stack and the program executed. 
  479.  
  480. When executed the program will initially prompt for 
  481. whether you wish to evaluate the product of area Ixy. 
  482. This is a most useful quantity particularly if you are 
  483. trying to establish whether the axis about which the 
  484. properties are being evaluated is a principle axis for 
  485. the section. A principle axis is one for which Ixy = 0. 
  486. An important restriction is placed on the use of "IBOX" 
  487. to evaluate Ixy and that is that successive coordinates 
  488. must not have the same x value. If this is the case and 
  489. you reply yes to evaluation of Ixy then a divide by zero 
  490. error will occur during program execution which will halt 
  491. the program with an 'ERROR' message. To avoid this the 
  492. input data should be checked to see whether a case arises 
  493. where successive coordinates do have the same x value. If 
  494. so then alter one of the x values by a very small amount 
  495. so as not to change the geometry too much, but enough to 
  496. ensure that a divide by zero error does not occur. Under 
  497. normal circumstances Ixy will not be required so that 
  498. entering any number other than zero will not invoke this 
  499. calculation. 
  500.  
  501. Upon successful program execution a single screen of 
  502. labelled output is obtained containing the quantities 
  503. described above. 
  504.  
  505.  
  506. ISEG 
  507.  
  508. The ISEG program evaluates the area, centroid and second 
  509. moment of area of a circular segment given the radius of 
  510. the circle and depth of segment. The second moment of 
  511. area is calculated about the centroidal axis of the 
  512. segment. 
  513.  
  514. The program takes 2 numbers from the stack: 
  515.  
  516.      Level 2 - radius of circle. 
  517.  
  518.      Level 1 - depth of segment. 
  519.  
  520. and returns the following: 
  521.  
  522.      Level 3 - Area of segment. 
  523.  
  524.      Level 2 - Centroid of segment measured from top of         
  525.                circle. 
  526.  
  527.      Level 1 - Second moment of area of segment. 
  528.  
  529.  
  530.  
  531.  
  532. VSEG 
  533.  
  534. VSEG is a program which calculates the volume under an 
  535. inclined plane which intersects a horizontal circular 
  536. area. This is equivalent to the volume of a circular 
  537. segment with varying height around the circumference of 
  538. the circle and a height of zero along the straight line 
  539. boundary of the segment. VSEG also calculates the 
  540. centroid of the volume measured from the top of the 
  541. circular segment. 
  542.  
  543. INPUT:    Level 3 - radius of circle. 
  544.  
  545.           Level 2 - depth of segment. 
  546.  
  547.           Level 1 - Max. height of plane above segment. 
  548.  
  549. OUTPUT:   Level 2 - Volume. 
  550.  
  551.           Level 1 - Centroid. 
  552. VCON - VOLUME OF A CONE 
  553.  
  554. Calculates the volume of a right cone. The base radius 
  555. and perpendicular height are entered in levels 2 and 1 of 
  556. the stack respectively. 
  557.  
  558.  
  559. VSPH - VOLUME OF A SPHERE 
  560.  
  561. Calculates the volume of a sphere given the radius in 
  562. level 1 of the stack. 
  563.  
  564.  
  565. SCON - SURFACE AREA OF A CONE 
  566.  
  567. Calculates the total surface area of a right cone 
  568. including the base area. The input is as for "VCON". 
  569.  
  570.  
  571. SSPH - SURFACE AREA OF A SPHERE 
  572.  
  573. Calculates the total surface area of a sphere given the 
  574. radius in level 1 of the stack. 
  575.  
  576.  
  577. CINT - CIRCLE INSCRIBED IN TRIANGLE 
  578.  
  579. Calculates the radius of a circle inscribed within a 
  580. triangle whose side lengths are specified in levels 1, 2 
  581. and 3 of the stack. The program returns the radius to 
  582. level 1. I have taken this program directly from "HP48 
  583. INSIGHTS Part 1: Principles and Programming" by William 
  584. C. Wickes. 
  585.  
  586.  
  587. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  588. Joe Muccillo 
  589. 66 Prospect St 
  590. Pascoe Vale, 3044 
  591. Melbourne 
  592. AUSTRALIA 
  593. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  594. @@G/GX Matrices 
  595. This is a "thread" from comp.sys.hp48 regarding the G/GX. 
  596.  
  597.  úÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ 
  598.  3 G SERIES HAS BETTER INTERNAL MATRIX ACCURACY THAN SX 3 
  599.  àÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄù 
  600.                     by Joseph K. Horn 
  601.  
  602. WOW, check this out. HP improved the ACCURACY of the 
  603. matrix functions in the G series!  Why don't they 
  604. advertise the fact?  This is great! 
  605.  
  606. Try out these examples. 
  607.  
  608. The inverse of 
  609.  
  610. [[ 58 59 ] 
  611.  [ 68 69 ]] 
  612.  
  613. (obtained by pressing 1/X) is supposed to be exactly 
  614.  
  615. [[ -6.9  5.9 ] 
  616.  [  6.8 -5.8 ]] 
  617.  
  618. and that's what the GX gets. And if you then invert 
  619. that, you get the original back, as you should. 
  620.  
  621. But the SX gets: 
  622.  
  623. [[ -6.89999999197  5.89999999314 ] 
  624.  [  6.79999999211 -5.79999999326 ]] 
  625.  
  626. Lots of wrong digits at the end of each element. 
  627. Re-invert, and you get: 
  628.  
  629. [[ 58.0000000022 59.0000000020 ] 
  630.  [ 68.0000000027 69.0000000023 ]] 
  631.  
  632. instead of the original. 
  633.  
  634. Even if you key in the correct inverse listed above, and 
  635. press 1/X on that, you *still* don't get the original 
  636. back. The SX just doesn't have the accuracy of the GX. 
  637.  
  638. Other examples to try: 
  639.  
  640. [[  79  94 ]     ÄÄ    [[  25 -18.8 ] 
  641.  [ 105 125 ]]           [ -21  15.8 ]] 
  642.  
  643. [[  3 101 ]      ÄÄ    [[ -36.7 10.1 ] 
  644.  [ 11 367 ]]            [   1.1  -.3 ]] 
  645.  
  646. GX gets these right. SX doesn't. 
  647.  
  648. Here's a fascinating and unexpectedly elegant proof of 
  649. the GX's superiority, brought to my attention by Rodger 
  650. Rosenbaum. Hilbert matrices are horribly ill-conditioned 
  651. and are a good test of a machine's accuracy. The 4x4 
  652. Hilbert matrix has this form: 
  653.  
  654. [[ 1/1 1/2 1/3 1/4 ] 
  655.  [ 1/2 1/3 1/4 1/5 ] 
  656.  [ 1/3 1/4 1/5 1/6 ] 
  657.  [ 1/4 1/5 1/6 1/7 ]] 
  658.  
  659. It can be obtained by running this 'HILBERT' program: 
  660.  
  661. HILBERT, by Joe Horn; n í  n-by-n Hilbert matrix 
  662.  
  663. (r) -> n 
  664.   (r) 1 n 
  665.     FOR j j DUP n + 1 - 
  666.       FOR k k INV 
  667.       NEXT 
  668.     NEXT { n n } ->ARRY 
  669.   ─ 
  670. ─ 
  671.  
  672. It has this as its exact inverse: 
  673.  
  674. [[   16  -120   240  -140 ] 
  675.  [ -120  1200 -2700  1680 ] 
  676.  [  240 -2700  6480 -4200 ] 
  677.  [ -140  1680 -4200  2800 ]] 
  678.  
  679. which I just verified using the Derive program. But if 
  680. you invert the 4x4 Hilbert matrix on your HP48, you'll 
  681. see elements that differ from the expected inverse listed 
  682. above. Until yesterday I'd have attributed this just to 
  683. round-off errors accumulating during the internal 
  684. calculation of the inverse. 
  685.  
  686. *** WRONG! ***   That's NOT primarily what's happening. 
  687. Here's proof. 
  688.  
  689. Here's what the SX gets: 
  690.  
  691. 16.0000000111 -120.000000119 240.000000282 -140.000000182 
  692. -120.000000124 1200.00000133 -2700.00000317 1680.00000205 
  693. 240.000000302 -2700.00000326 6480.00000779 -4200.00000504 
  694. -140.000000199 1680.00000216 -4200.00000516 2800.00000334 
  695.  
  696. Lots of wrong digits. But do the same process on the 
  697. "more accurate" GX and you get even worse-looking 
  698. results: 
  699.  
  700. 16.0000000325 -120.000000365 240.000000882 -140.000000575 
  701. -120.000000365 1200.00000411 -2700.00000995 1680.00000649 
  702. 240.000000882 -2700.00000995 6480.00002408 -4200.00001572 
  703. -140.000000576 1680.00000650 -4200.00001572 2800.00001027 
  704.  
  705. If the GX is more accurate, why are its results all worse 
  706. than the SX's results?  The answer is that the HP48 NEVER 
  707. CONTAINED the Hilbert matrix. For example, the third 
  708. element is supposed to be 1/3, right? But the HP48 only 
  709. had the first 12 digits of 1/3 (0.333333333333) in that 
  710. position, not 1/3. Thus we need to test a new 
  711. hypothesis: could the GX result actually be the CORRECT 
  712. answer, given that the values in the matrix were rounded 
  713. off to 12 places BEFORE the inverse was calculated? 
  714.  
  715. To test this, I typed the following into Derive, setting 
  716. the calculation accuracy to 20 places and the notation to 
  717. 12 digits: 
  718.  
  719. 1.00000000000 .500000000000 .333333333333 .250000000000 
  720. .500000000000 .333333333333 .250000000000 .200000000000 
  721. .333333333333 .250000000000 .200000000000 .166666666667 
  722. .250000000000 .200000000000 .166666666667 .142857142857 
  723. .200000000000 .166666666667 .142857142857 .125000000000 
  724.  
  725. That is what you REALLY get when you run 'HILBERT' on the 
  726. HP48, not the idealized matrix of reciprocals listed 
  727. above. 
  728.  
  729. Inverting this in Derive yields what the HP48 SHOULD get: 
  730.  
  731. 16.0000000325 -120.000000366 240.000000884 -140.000000576 
  732. -120.000000366 1200.00000412 -2700.00000997 1680.00000651 
  733. 240.000000884 -2700.00000997 6480.00002413 -4200.00001575 
  734. -140.000000576 1680.00000651 -4200.00001575 2800.00001029 
  735.  
  736. Compare this to what the GX gets!  Almost the same!  The 
  737. very worst error is only 5 off in the 12th place. So the 
  738. "errors" that we mistakenly attributed to faulty 
  739. calculations were in fact due to faulty inputs, and our 
  740. hypothesis is validated. The SX, however, has errors 
  741. propagating all the way up to the 9th decimal place. The 
  742. GX therefore is superior to the SX in matrix math 
  743. accuracy. 
  744.  
  745. ííííí 
  746. jurjen@q2c.nl [Jurjen N.E. Bos] writes: 
  747.  
  748. > This is indeed remarkable. It looks like they have 
  749. > using a special super-long type (like 24 digits instead 
  750. > of 15) for the internal multiplications. Did anyone 
  751. > check the speed? 
  752.  
  753. SX, normal INV of 4x4 Hilbert: 0.895_s 
  754. GX, normal INV of 4x4 Hilbert: 0.645_s 
  755.  
  756. SX, Jurjen's RSD improvement : 2.427_s 
  757. GX, Jurjen's RSD improvement : 1.685_s 
  758.  
  759. Both are roughly 30% faster for the GX. 
  760.  
  761. > By the way: [using RSD] will also [work] on the G(X), 
  762. > and probably improve the accuracy to even higher 
  763. > standards. Can anyone with a G(X) handy check this out? 
  764.  
  765. Using RSD on the GX yields identical results as on the SX 
  766. for a 4x4 Hilbert, but begins to differ already for a 
  767. 5x5. Using Toby's method to calculate the absolute error 
  768. gives these "number of wrong digits" values for the 
  769. Hilbert matrices of various sizes: 
  770.  
  771. TABLE OF "NUMBER OF WRONG DIGITS" USING TOBY'S METHOD 
  772.  
  773. Hilbert          --GX--              --GX-- INV plus 
  774.  Order         INV alone             one RSD iteration 
  775.  
  776.    4                  28                         5 
  777.    5               1,192                       978 
  778.    6               8,769                    58,705  <--?? 
  779.    7           1,925,587                 1,885,921 
  780.    8         120,327,605                59,548,237 
  781.    9       2,968,381,031               939,982,230 
  782.   10      37,012,693,951            17,062,216,102 
  783.  
  784. Hilbert          --SX--              --SX-- INV plus 
  785.  Order         INV alone             one RSD iteration 
  786.  
  787.    4               9,628                         5 
  788.    5             417,984                       691  <--!! 
  789.    6           7,164,844                    39,383  <--!! 
  790.    7          33,256,221                 1,842,570  <--!! 
  791.    8         464,357,873                53,018,430  <--!! 
  792.    9      43,094,094,759               997,947,848 
  793.   10   2,833,599,816,259           208,556,942,563 
  794.  
  795. Calculations were done by Derive with precision set to 64 
  796. internal digits, truncated to 15 digits, then rounded to 
  797. 12 digits. 
  798.  
  799. That the GX beats the SX using a naked INV is no 
  800. surprise. But there are two surprising things in the RSD 
  801. columns. First, using RSD on a 6x6 Hilbert inversion 
  802. makes it WORSE on the GX than just using INV alone (the 
  803. number of wrong digits rises from 8769 to 58705!). 
  804. Second, using RSD on the SX seems to give better final 
  805. results than using RSD on the GX more often than not! 
  806. What gives?  HP improved INV but not RSD, such that RSD's 
  807. inaccuracy can prove counterproductive???  Is using RSD 
  808. on a GX INV akin to attaching an antenna to improve the 
  809. picture quality on a cable TV? 
  810.  
  811. ííííí 
  812. Reply from paulm@hpcvra.cv.hp.com [Paul McClellan], the 
  813. HP team member responsible for improving the matrix code: 
  814.  
  815. The S/SX computed matrix inverses and system solutions 
  816. in-place, computing inner products to 15 digits of 
  817. precision but rounding computed quantities to 12 digits 
  818. of precision before storing them in the array. RSD 
  819. generally improves the SX results because the residuals 
  820. are computed to 15 digits of precision, then rounded to 
  821. 12 digits. RSD can thereby provide useful information 
  822. for iterative refinement. 
  823.  
  824. The G/GX computes matrix inverses and system solutions to 
  825. full 15 digits of accuracy, rounding only the final 
  826. results of the computation. These operations use 
  827. 15-digit versions of their array arguments internally. 
  828. RSD was not changed, and in general it no longer provides 
  829. useful information for iterative refinement, as you have 
  830. determined empirically. 
  831.  
  832. My experience is that using RSD on the SX will not 
  833. generally give better results than "naked" GX results. 
  834. As the ill-conditioning of the problem increases, 
  835. eventually the three extra digits one recovers via the 
  836. SX's RSD is overwhelmed by errors in the 12-digit 
  837. computations. Your data illustrates this with Hilbert 
  838. matrices of order 9 and 10. 
  839.  
  840. It would have been helpful had we computed the G/GX RSD 
  841. to double precision before rounding to 12 digits. This 
  842. would have made it useful for iterative refinement. We 
  843. ran out of resources and did not do so. However, this 
  844. can be done by implementing double precision arithmetic 
  845. in user RPL. Two references I have on the subject are: 
  846.  
  847. Dekker, T.J. "A floating-point technique for extending 
  848. the available precision", Numer. Math. 18 (1971) 224-242. 
  849.  
  850. Linnainmaa, S. "Software for doubled-precision 
  851. floating-point computations", ACM Trans. Math. Soft. Vol 
  852. 7. No 3 (Sept 1981) 272-283. 
  853.  
  854. [Note: See Digi24 on this disk for an HP48 implementation 
  855.  of the algorithms in the first reference above.  -jkh-] 
  856. @@Digi24     SG 
  857. By: rodger@hardy.u.washington.edu [Rodger Rosenbaum] 
  858. Date: 09 Nov 1993 
  859.  
  860.             Éííííííííííííííííííííííííííííííí» 
  861.             º Double Precision on the HP-48 º 
  862.             èííííííííííííííííííííííííííííííí¼ 
  863.  
  864.     Here are some routines based on a paper that appeared 
  865. in Numerische Mathematik in 1971, page 224. The paper 
  866. was written by T.J. Dekker and is entitled "A 
  867. Floating-Point Technique for Extending the Available 
  868. Precision." Dekker's method requires that the single 
  869. precision arithmetic used in the machine under 
  870. consideration meet rather severe requirements, such as 
  871. impeccable rounding. Fortunately, recent HP machines do; 
  872. most other calculators do not, so Dekker's method will 
  873. probably fail on them. In this method, a double precision 
  874. number is represented as two single precision numbers. I 
  875. have chosen not to do the obvious and let the two halves 
  876. of a complex number on the HP-48 be one double precision 
  877. number. Instead, one double precision number is 
  878. represented by two single precision numbers on separate 
  879. levels of the stack. The reason I have done this is 1: 
  880. Because the HP-48 allows a scalar to multiply a vector in 
  881. one operation and this greatly simplifies and speeds up 
  882. double precision Gaussian elimination, and 2: Because 
  883. this way double precision arithmetic can be done on 
  884. complex numbers. I do not know that the results are 
  885. accurate when using complex numbers in the way that 
  886. Dekker proves they are when using reals, but my empirical 
  887. testing indicates that they are. I would be glad to hear 
  888. of any counterexamples. 
  889.  
  890.                        úÄÄÄÄÄÄÄÄÄÄ¿ 
  891.                        3 Examples 3 
  892.                        àÄÄÄÄÄÄÄÄÄÄù 
  893.  
  894. A double precision number is represented as two single 
  895. precision numbers on the stack. For example, double 
  896. precision 2 is represented as: 
  897.  
  898.     2:     2 
  899.     1:     0 
  900.      
  901. now put double precision 3 on the stack: 
  902.  
  903.     4:     2 
  904.     3:     0 
  905.     2:     3 
  906.     1:     0 
  907.      
  908. now multiply them by executing MUL2: 
  909.  
  910.     2:     6 
  911.     1:     0 
  912.      
  913. A double precision complex number, (1,1) is: 
  914.  
  915.     2:    (1,1) 
  916.     1:    (0,0) 
  917.      
  918. Take the square root by executing SQR2: 
  919.  
  920.     2:  (1.09868411347,.455089860562) 
  921.     1:  (-2.19003396021E-12,2.27341304364E-13) 
  922.      
  923. now execute DUP2 MUL2 and see the original (1,1). 
  924.  
  925. Double precision numbers can be typed in conveniently by 
  926. just adding a comma (or space) and a zero to insert the 
  927. least significant part; for example, 2*3 in double 
  928. precision could be done by typing 2,0 ENTER 3,0 ENTER 
  929. MUL2. 
  930.  
  931. Notice that after a sequence of operations using double 
  932. precision, the double precision result on the stack can 
  933. be converted to single precision by just pressing +. 
  934.       
  935.      úÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ 
  936.      3 Description of the Double Precision Routines 3 
  937.      àÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄù 
  938.  
  939. SPLT:  This routine splits a single precision number into 
  940. two parts as required by Dekker's algorithm. 
  941.  
  942. MUL:  This routine multiplies two single precision 
  943. numbers and returns a double precision product. It is 
  944. used as an auxiliary routine by MUL2, DIV2, and SQR2. 
  945.  
  946. ADD2, SUB2, MUL2, DIV2:  These routines expect two double 
  947. precision arguments on the stack (occupying four levels) 
  948. and compute the double precision result suggested by 
  949. their names. One of the arguments, but not both, may be 
  950. a vector or matrix when MUL2 is executed; the dividend 
  951. may be a vector or matrix when DIV2 is used. None of the 
  952. arguments may be a vector or matrix when using ADD2 or 
  953. SUB2. Complex arguments may be used with all four 
  954. routines. Thus, to multiply [1 2 3] x 5 the stack must 
  955. be set up like this: 
  956.  
  957.       4:[1 2 3] 
  958.       3:[0 0 0] 
  959.       2:  5 
  960.       1:  0 
  961.        
  962.    then execute MUL2 and see the double precision result: 
  963.     
  964.       2:[5 10 15] 
  965.       1:[0 0 0] 
  966.        
  967. SQR2:  This routine computes a double precision square 
  968. root. Type in: 
  969.    
  970.       2:5 
  971.       1:0 
  972.        
  973.    Execute SQR2 and see a peculiarity of Dekker's method. 
  974.    The result on the stack is: 
  975.     
  976.       2:   2.2360679775 
  977.       1:  -2.10303590826E-13 
  978.        
  979.    notice that the least significant part of the result 
  980.    is negative. This is an artifact of Dekker's method, 
  981.    which brings me to the next routine. 
  982.     
  983.     
  984. SHO2:  This routine converts one double precision real 
  985. scalar (note, scalar only) on the stack to two strings on 
  986. the stack. The most significant part will be shown in 
  987. scientific format; the least significant part will be 
  988. shown as twelve digits. If the least significant twelve 
  989. digits are inserted just in front of the letter E in the 
  990. most significant part, this will be the final 24 digit 
  991. result. I have left the two parts separate on the stack 
  992. so that they can both be seen without recourse to the 
  993. EDIT or VISIT function. Notice that the SHO2 routine 
  994. takes care of the possibility that the least significant 
  995. part is negative in Dekker's format, as in the square 
  996. root of 5 example above. Another thing taken care of by 
  997. SHO2 is demonstrated by taking the double precision 
  998. square root of 163. Type in: 
  999.  
  1000.      2:  163 
  1001.      1:    0 
  1002.       
  1003.    and then execute SQR2; see on the stack: 
  1004.     
  1005.      2:    12.7671453348 
  1006.      1: 3.70466171095E-12 
  1007.       
  1008.    now execute SHO2 and see: 
  1009.     
  1010.      2:  "1.27671453348E1" 
  1011.      1:     "037046617109" 
  1012.       
  1013. This represents the number:  12.7671453348037046617109 
  1014. Notice that after executing SHO2 it can be seen that 
  1015. there is a leading zero in the least significant part 
  1016. that was not obvious before. Also notice that SHO2 does 
  1017. not properly round the last digit of the least 
  1018. significant part, but merely truncates it. 
  1019.  
  1020. SHO2 will not work with a double precision vector on the 
  1021. stack; an element of the vector (both parts) must be 
  1022. extracted with GET and then converted with SHO2. An 
  1023. example of this is the routine LOOK which is designed to 
  1024. display the results of a double precision Gaussian 
  1025. elimination; see below. Nor will SHO2 work with complex 
  1026. numbers directly; the respective real or imaginary most 
  1027. significant and least significant parts must be extracted 
  1028. and then SHO2 can be used. 
  1029.  
  1030. QAD: This routine uses double precision arithmetic to 
  1031. solve the general quadratic equation, Ax^2+Bx+C. Put the 
  1032. values A,B,C on the stack and execute QAD. The roots are 
  1033. given only to single precision, but the discriminant is 
  1034. computed with double precision; thus the example given in 
  1035. the last pages of the HP-15 Advanced Functions handbook 
  1036. is solved correctly. 
  1037.  
  1038.       úÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ 
  1039.       3 Gaussian Elimination and Back Substitution 3 
  1040.       àÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄù 
  1041.  
  1042. It is possible to do a double precision solution of a 
  1043. linear system with these routines. Assume that on the 
  1044. stack is a right-hand side vector (or matrix) of 
  1045. constants and a matrix of coefficients, e.g.: 
  1046.  
  1047.        2:  [[ 1 ] 
  1048.             [ 7 ] 
  1049.             [ 9 ]] 
  1050.        1:  [[ 1 2 3 ] 
  1051.             [ 7 5 2 ] 
  1052.             [ 3 5 4 ]] 
  1053.              
  1054. First, these two must be converted to an augmented matrix 
  1055. by executing AUGM. See: 
  1056.  
  1057.         6: [ 1 2 3 1 ] 
  1058.         5: [ 0 0 0 0 ] 
  1059.         4: [ 7 5 2 7 ] 
  1060.         3: [ 0 0 0 0 ] 
  1061.         2: [ 3 5 4 9 ] 
  1062.         1: [ 0 0 0 0 ] 
  1063.           
  1064. This represents a double precision augmented matrix. Now 
  1065. execute ELIM and see the results of double precision 
  1066. Gaussian elimination: 
  1067.  
  1068.         6: [ 1 .714285714286 .285714285714 1 ] 
  1069.         5: [ 0 -2.85714285714E-13 2.85714285714E-13 0 ] 
  1070.         4: [ 0 1 1.1 2.1 ] 
  1071.         3: [ 0 0 3.5E-24 3.5E-24 ] 
  1072.         2: [ 0 0 1.3 -2.7 ] 
  1073.         1: [ 0 0 1.E-23 1.E-23 ] 
  1074.          
  1075. In order to see all 24 digits of the (1,2) element (for 
  1076. example) of the solution, which has a negative least 
  1077. significant part, execute: 6 PICK 2 GET 6 PICK 2 GET SHO2 
  1078. and see: 
  1079.  
  1080.          3: [ 0 0 1.E-23 1.E-23... 
  1081.          2:   "7.14285714285E-1" 
  1082.          1:       "714285714286" 
  1083.           
  1084. Now, to complete the solution, drop the two strings and 
  1085. execute BACK which will do back substitution. The stack 
  1086. now contains: 
  1087.  
  1088.          6: [ 1 0 0 -1.53846153846 ] 
  1089.          5: [ 0 0 0 -1.53846153845E-12 ] 
  1090.          4: [ 0 1 0 4.38461538462 ] 
  1091.          3: [ 0 0 0 -4.6153846154E-12 ] 
  1092.          2: [ 0 0 1 -2.07692307692 ] 
  1093.          1: [ 0 0 0 -3.0769230769E-12 ] 
  1094.           
  1095. Now, to see the solution elements as strings, use LOOK. 
  1096. To see the first element of the solution, type 1 LOOK; to 
  1097. see the second, type 2 LOOK; etc. Don't forget to drop 
  1098. the two strings of the previous result before executing 
  1099. LOOK again. 
  1100.  
  1101. The routine PeVAL does the same thing as the PEVAL 
  1102. function in the HP-48GX, but the results are computed and 
  1103. accumulated in double precision. The final result is 
  1104. returned as a standard single precision REAL. If a 
  1105. double precision final result is wanted, delete the final 
  1106. + in the routine PeVAL. 
  1107.  
  1108.                        úÄÄÄÄÄÄÄÄÄ¿ 
  1109.                        3 SUMMARY 3 
  1110.                        àÄÄÄÄÄÄÄÄÄù 
  1111.  
  1112. ELIM:  Does double precision Gaussian elimination. 
  1113.  
  1114. BACK:  Does back substitution after elimination. 
  1115.  
  1116. UNIT:  Divides a row by its pivot element. 
  1117.  
  1118. RED:   Reduces the remaining rows of the augmented matrix 
  1119.        by the pivot row. 
  1120.  
  1121. PIV:   Does partial pivoting 
  1122.  
  1123. PIVX:  Another partial pivoting routine; does it as shown 
  1124.        in most textbooks. 
  1125.  
  1126. EXG:   Exchanges double precision rows. 
  1127.  
  1128. MAKE:  An auxiliary routine used by AUGM. It creates a 
  1129.           row vector of all zeroes to represent the least 
  1130.           significant part of a double precision vector. 
  1131.  
  1132. GAUS:  Does the whole job in double precision. GAUS 
  1133.           expects a problem to be set up just the way the 
  1134.           HP-48 expects it, with a column vector (or 
  1135.           matrix) on level 2 of the stack and a square 
  1136.           matrix on level 1, to be solved by pressing the 
  1137.           divide key. 
  1138.  
  1139. PeVAL: Evaluates a polynomial. Put the vector of 
  1140.        coefficients on stack level 2 and the value of the 
  1141.        independent variable on level 1. 
  1142.  
  1143.  
  1144. SWP2, OVR2, ROT2, PCK:  Double precision utilities. 
  1145. @@LAPLACE    SG 
  1146. (Comp.sys.hp48) 
  1147. Item: 1357 by meissner@triton.unm.edu [John Meissner] 
  1148. Subj: Lalpace_jm -- New Version. 
  1149. Date: 04 Jul 1992 
  1150.  
  1151. [Note: John makes several references to Wayne Scott's 
  1152.  POLY software. Details about POLY can be found on 
  1153.  Goodies Disks 1 and 7. -jkh-] 
  1154.  
  1155.      These routines are an upgrade to my previous Laplace 
  1156. transform utility. Many of the new programs have been 
  1157. rewritten in SYSTEM-RPL. As always, system RPL can cause 
  1158. some unpredictable things to happen -- including MEMORY 
  1159. LOST errors. 
  1160.  
  1161.      I have strived to do my best to make the routines 
  1162. safe, but I am new to syystem-RPL programming and there 
  1163. are undoubtedly some bugs still left in the routines. I 
  1164. am posting these routine to comp.sys.hp48 so that these 
  1165. bugs can be tested and corrected over the next few weeks 
  1166. so that I can release some kind of a final product. 
  1167.  
  1168.    VERY IMPORTANT! DO NOT USE THESE ROUTINES UNLESS YOU 
  1169. ARE WILLING TO SUFFER A MEMORY LOST!  I have not had any 
  1170. of these types of problems for a month or so, but they 
  1171. can happen so beware. I have tested these routines 
  1172. somewhat extensively and have no trobel to reoprt. If 
  1173. problems do arise of aby kind a would appreciate people 
  1174. dropping me a line and letting me fix them. After a few 
  1175. weeks I will post a more finalized version to 
  1176. comp.sources.hp48. In the interim, keep the bug reports 
  1177. rolling in. 
  1178.  
  1179.          Summary of changes in these routines: 
  1180.  
  1181.          1) system-RPL, these routines run 5 to 10 times 
  1182.          faster. 
  1183.  
  1184.          2) Remove flags [0-5] usage. 
  1185.  
  1186.          3) Fixed bugs in & and RT-> that caused 
  1187.          incorrect transforms. 
  1188.  
  1189.          4) install a patch that allows 't' to exists 
  1190.          elsewhere in the PATH. 
  1191.  
  1192.          5) Remove 'e^t' notation. 
  1193.  
  1194.          6) Recognizes and handles correctly the 'SQ()' 
  1195.          function. 
  1196.  
  1197.          7) Many changes in how the routines work that 
  1198.             speed up or otherwise enhance their 
  1199.             performance. 
  1200.  
  1201.      The origional routines used Wanye Scotts polinomial 
  1202. routines for most of the grunt work. I don't think any 
  1203. of Wayne's routines are still in this package, but he 
  1204. deserves credit for the notation and ultimately these 
  1205. routines since I never would have bothered without his 
  1206. work. 
  1207.  
  1208.      Also, Bill Wickes' port of a polynomial root finder 
  1209. is included in these routines. Thank you Bill for the 
  1210. efforts. 
  1211.  
  1212.          The remainder of this article is an edited 
  1213. version of my original post. 
  1214.  
  1215.      The following programs are released to the public 
  1216. domain provided that no money exchange hands (unless of 
  1217. course my hands are involved) 
  1218.  
  1219.      A few disclaimers are in order. 
  1220.  
  1221.      1) The routines in this directory use Wayne Scott's 
  1222. polynomial root finder routines extensively. Beware -- 
  1223. if you already have these routines and use them, then you 
  1224. need to read all of these documents to determine what 
  1225. effects might surface. For the most part, these routines 
  1226. are entirely different even though they do accomplish 
  1227. some of the same tasks. 
  1228.  
  1229.      2) If you are unfamiliar with the format of the 
  1230. polynomials used by Wayne's routines, here is a brief 
  1231. refresher: 
  1232.  
  1233. the polynomial   :       x^4 - 3*x^3 - 2*x -1 
  1234. is represented as:       { 1 -3 0 -2 -1 } 
  1235.  
  1236.      This is to say the first element of the list is the 
  1237. coefficient for the x^4 term and so on through the 
  1238. equation. It is customary to use 's' for the Laplace 
  1239. variable, so from here on, I will use 's' in my examples. 
  1240.     
  1241.         Some of the routines require two polynomials on 
  1242. the stack. For example, the ratio of the two polynomials 
  1243. representing this expression: 
  1244.  
  1245.                 3*s^5 - 3*s^3 + 5*s^2 - 2 
  1246.          --------------------------------------- 
  1247.          s^5 - 7*s^4 + 15*s^3 - 5*s^2 -16*s + 12 
  1248.  
  1249. would be represented on the stack as: 
  1250.                     
  1251.                    2:  {3 0 -3 5 0 -2} 
  1252.                    1:  {1 -7 15 -5 -16 12} 
  1253.  
  1254. Another method of representing the same ratio is: 
  1255.  
  1256.              2:  {3 0 -3 5 0 -2) 
  1257.              1:  {3 2 2 1 -1} 
  1258.  
  1259.      where level 2 contains the same list as the previous 
  1260. example. However, level 1 contains the roots of the 
  1261. denominator. 
  1262.  
  1263.      Hopefully, these examples are clear enough for you 
  1264. to get the picture. 
  1265.  
  1266.      The following are descriptions and examples of each 
  1267. of the functions in the LAPLACE directory: 
  1268.  
  1269.  
  1270.      This variable returns an unevaluated copy of itself. 
  1271. I allows the routines to operate when ther is another 't' 
  1272. defined in the current path. It is also useful for keying 
  1273. is formulae. Since the independant variable for these 
  1274. routines must be 't' 
  1275.  
  1276. ->L 
  1277.  
  1278.      This program takes an algebraic object and returns 
  1279. its Laplace Transform. The input function must be a 
  1280. function of 't'  that is to say that the only independent 
  1281. variable in the function must be lower case t. The 
  1282. functions that it recognizes are constants, exponentials, 
  1283. sines, cosines, and polynomials. The program should 
  1284. allow any combinations of multiplication, addition, 
  1285. subtraction, and integer exponents. Division by non 
  1286. constants is not supported however. For example: 
  1287.  
  1288. 1: 'COS(2*t)^2' 
  1289. ->L 
  1290.  
  1291. after a pause will return : 
  1292.  
  1293. 2: { 1 0 2 }              ; numerator  
  1294. 1: { (0,4) (0,0) (0,-4) } ; roots of the denominator  
  1295.   
  1296.    
  1297.      This represent the transform. With this as an 
  1298. input, the inverse transform function returns : 
  1299.  
  1300. L-> 
  1301.  
  1302. 1: '1/2 + 1/2*COS(4*t)' 
  1303.  
  1304.      This doesn't look the same as the original function; 
  1305. but, the answer is correct. COS(t)^2 = 1/2 + 
  1306. 1/2*COS(2+t) is a trigonometric identity. Kinda nifty 
  1307. eh? 
  1308.  
  1309.      Another interesting result of the transformation is 
  1310. integration. Integration in the time domain is division 
  1311. by s in the s domain. So, take the function: 
  1312.  
  1313. 1: 'EXP(-2*t)*COS(t)^2' 
  1314.  
  1315. ->L 
  1316.  
  1317. Returns: 
  1318.  
  1319. 2: {1 4 6 } 
  1320. 1: { (-2,2) (-2,0) (-2,-2) } 
  1321.  
  1322.      The list on level one is the roots of the 
  1323. denominator. If you add a zero to the list ( edit the 
  1324. list or just put a zero on the stack and press the + key 
  1325. ) you are effectively multiplying the denominator by s. 
  1326. This is the same as dividing the fraction by s. The 
  1327. result in the time domain, after the inverse transform is 
  1328. done, is the integration of the original function between 
  1329. the limits of 0 and 't.' For example: 
  1330.  
  1331. 2: { 1 4 6 } 
  1332. 1: { (-2,2) (-2,0) (-2,-2) 0 } 
  1333. ->L 
  1334.  
  1335. Returns: 
  1336.  
  1337. 1: '3/8-1/8*EXP(-(2*t))*COS(2*t)+1/8*EXP(-(2*t))*SIN(2* 
  1338.    t)-1/4*EXP(2*t)' 
  1339.  
  1340.      This is the integral of the original function 
  1341. evaluated between 0 and t. In many cases the general 
  1342. solution can be obtained by replacing the constant (in 
  1343. this case 3/8) with a general constant of integration. 
  1344. Needless to say, this method of integration was a little 
  1345. easier than looking in the integral tables. The 
  1346. description of the inverse Laplace Transformer follows. 
  1347.  
  1348. L-> 
  1349.      This program takes the numerator, level 2, and the 
  1350. denominator, level 1 (factored), and returns its inverse 
  1351. Laplace Transform. The factors of the denominator need 
  1352. not be grouped together as Wayne's routines require since 
  1353. they are sorted before anything is done to them. I 
  1354. originally wrote this routine and uploaded it to hpcvbbs, 
  1355. but I did not include much for documentation. Since then 
  1356. I have seen it posted a few times and have heard of some 
  1357. bugs that I am unable to duplicate. This may be because 
  1358. the users are using Wayne's routines with this one, or, I 
  1359. fixed the bugs and don't remember. Either way here is 
  1360. the latest version. 
  1361.  
  1362.      The routine should correctly transform the ratio of 
  1363. any two polynomials with real coefficients. The only 
  1364. limitation i know of is that the numerator should be of 
  1365. lower order than the denominator. You may still get the 
  1366. correct answer if this condition is not met but there are 
  1367. no guarantees. 
  1368.  
  1369.      I have found absolutely no problems with this 
  1370. routine. In fact, I have found 2 errors in the transform 
  1371. tables of the "CRC Handbook of Mathematical Formulas.'  I 
  1372. am not willing to say that there are no bugs because I am 
  1373. sure they exist. Please let me know as they become 
  1374. apparent. I have been truly amazed with the results this 
  1375. program returns;  Wayne did a good job with his routines. 
  1376. He did almost all of the work. Here is and example: 
  1377.  
  1378. 2: { 2 0 4 } 
  1379. 1: { 1 1 0 4 } 
  1380. L-> 
  1381.  
  1382. Returns:  
  1383.  
  1384. 1:'-1 - 2*t*EXP(t) + EXP(4*t)' 
  1385.  
  1386. RT-> 
  1387.  
  1388.      The results of this routine are different depending 
  1389. on the number of lists on the stack. If there are 2 
  1390. lists of numbers on the stack, the routine will assume 
  1391. that the represent a fraction and the numerator is 
  1392. divided by the coefficient of the highest order term in 
  1393. the denominator. This is necessary to keep the ratio 
  1394. correct since this term is lost in the expasion. In the 
  1395. event that the stack contains only one list this program 
  1396. returns the roots of that list sorted. 
  1397.  
  1398. 1: { 1 -6 1 24 -20 } 
  1399. RT-> 
  1400.  
  1401. returns: 
  1402. 1: { 1 2 -2 5 } 
  1403.  
  1404. FADD 
  1405.  
  1406.      This routine adds two partial fractions. They must 
  1407. be in the form: 
  1408.  
  1409. 4: list    (numerator) 
  1410. 3: list    (denominator roots) 
  1411. 2: list    (second nemerator) 
  1412. 1: list    (second denominator roots) 
  1413.  
  1414.  
  1415.      This routine convolves (sp?) Two partial fractions. 
  1416. It is used by the routine ->L. It either does a partial 
  1417. fraction expansion of one of the two terms and then does 
  1418. an 's' shifted summation of the terms, or is does a 
  1419. straight multiplication of the terms -- depending on 
  1420. which is appropriate. It is still written in user-RPL 
  1421. since there was no real speed increase when I rewrote it. 
  1422. I believe that user-RPL should be used whenever possible 
  1423. to avoid as many headaches as possible. 
  1424.  
  1425.  
  1426. SORT 
  1427.  
  1428.      Fairly self explanatory. Not the bubble variety. 
  1429. It is much smaller than the bubble sorts that I tried and 
  1430. is a little faster for lists that are shorter than about 
  1431. 20 elements. The sort order is largest to smallest with 
  1432. weighting on the real value. This means that the 
  1433. unstable roots will be at the begining of the list if 
  1434. they exist. 
  1435.  
  1436. RED 
  1437.  
  1438.      This routine uses PDIV to remove any common roots in 
  1439. the numerator and denominator. It is slow but necessary 
  1440. if you are working with complex transforms. 
  1441.  
  1442.    
  1443.      This routine takes an object from the stack and 
  1444. attempts to rationalize it to within 5 digits of 
  1445. accuracy. In other words, if you have a nomber like 
  1446. 5.200004543 and want to round it to the nearest fraction 
  1447. then Q is your program. It is necessary because the 
  1448. roots returned by the root finder are not exact. And the 
  1449. calculator drops digits here and there when dividing or 
  1450. finding roots. The routine will also accept lists, 
  1451. algebraics, complex numbers, and combinations of any of 
  1452. the above. 
  1453.  
  1454. PMUL 
  1455.  
  1456.      This routine take two polynomials and returns their 
  1457. products. I have completely rewritten this program to 
  1458. speed it up and slightly change the function. The 
  1459. objects do not have to be lists. The routine will now 
  1460. multiply a list by a constant. It should function 
  1461. identically to wayne's routines other than this change. 
  1462.  
  1463. IRT 
  1464.  
  1465.      This routine take the roots of the polynomial and 
  1466. multiplies them to find the polynomial. 
  1467.  
  1468. PADD 
  1469.  
  1470.      This routine takes two polynomials and adds them. 
  1471.  In addition, if the object on level 1 is a number (real 
  1472.  or complex), the routine adds the number to each of the 
  1473.  elements in the list in the other stack level. These 
  1474.  changes were made in the interest of speed. 
  1475.  
  1476. TRIM 
  1477.   
  1478.      This routine takes a list and performs Q and then 
  1479. strips the leading zeros. It works identically to the 
  1480. original I believe. 
  1481.  
  1482. PDIV 
  1483.  
  1484.      This routine is NOT the same a Wayne's. This 
  1485. routines accepts a list, representing a polinomial, and a 
  1486. number, representing a root of the polinomial, and 
  1487. returns the list with that root divided out and the 
  1488. remainder which is also the value of the polinomial 
  1489. evaluated at that root. Example 
  1490.  
  1491. 2:  { 1 -2 1 } 
  1492. 1:  1 
  1493.  
  1494. PDIV  (returns) 
  1495.  
  1496. 2: 0 
  1497. 1: { 1 -1 } 
  1498.  
  1499. RDER 
  1500.   
  1501.      This routine takes two lists (numerator,denominator) 
  1502. and returns the numerator of the derivative of the ratio. 
  1503.  
  1504. PDER 
  1505.   
  1506.      Same as above except just for one polynomial and 
  1507. returns the derivative of that polynomial. 
  1508.  
  1509. PF 
  1510.  
  1511.      Does partial fraction expansion of the ratio 
  1512. (numerator, roots) on the stack. 
  1513.  
  1514. Please let me know id this program is in any way useful 
  1515. to amy of you. Also please let me know of any 
  1516. suggestions or bugs that occur. 
  1517.  
  1518. Good luck, 
  1519.  
  1520. John Meissner 
  1521. @@MATRIX     SG 
  1522. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  1523. Subj:  Matrix Utilities 
  1524. Author: Joe Muccillo 
  1525. Date: 23 Sept. 1993 
  1526. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  1527.  
  1528. Here are 10 matrix utility programs which I have found to 
  1529. be useful in a variety of applications. I have compiled 
  1530. them into a library ( 800: MATRIX ) in order to make it 
  1531. easier to access them as subroutines. If anyone has any 
  1532. queries regarding these programs write to the address 
  1533. shown below. 
  1534.  
  1535.  
  1536.  
  1537. GETCO 
  1538.  
  1539. "GETCO" or GET COLUMN is used to retrieve specified 
  1540. columns from an array. The columns to be retrieved are 
  1541. specified in a list with { } dilimiters which is placed 
  1542. in level 1 of the stack. The array is placed in Level 2. 
  1543. The output is a matrix containing the listed columns only 
  1544. and redimensioned to suit. The list of columns to be 
  1545. retrieved must contain integer values no greater than the 
  1546. width of the matrix in level 2. Any zero elements in 
  1547. this list are ignored by the program. 
  1548.  
  1549. Eg: Level 2    [[  1  3  5  7 ] 
  1550.                 [ 16  2  4 11 ] 
  1551.                 [  4  9 10  3 ]] 
  1552.  
  1553.     Level 1    { 1 0 3 } 
  1554.  
  1555.     Result     [[  1  5 ] 
  1556.                 [ 16  4 ] 
  1557.                 [  4 10 ]] 
  1558.  
  1559. GETRO 
  1560.  
  1561. This utility is similar to "GETCO" except that it 
  1562. retrieves rows rather than columns. 
  1563.  
  1564.  
  1565. KERO 
  1566.  
  1567. "KERO", short for KEEP ROW, retrieves a range of rows 
  1568. from a given array. The program takes as its arguments a 
  1569. matrix from Level 3 and two integers defining the start 
  1570. and end rows of a range. These are in Levels 2 and 1 
  1571. respectively. 
  1572.  
  1573. Eg. Level 3    [[ 10  2 12 ] 
  1574.                 [  2  7  9 ] 
  1575.                 [  4  8 10 ] 
  1576.                 [ 13  9 11 ]] 
  1577.  
  1578.     Level 2     2 
  1579.     Level 1     3 
  1580.     Result     [[ 2  7  9 ] 
  1581.                 [ 4  8 10 ]] 
  1582.  
  1583. COPRO 
  1584.  
  1585. "COPRO" will copy a specified row in a matrix to other 
  1586. rows a specified number of times. This program takes 4 
  1587. arguments from the stack and returns a single item - the 
  1588. resultant matrix to Level 1 of the stack. The 4 
  1589. arguments required are: 
  1590.  
  1591.  1 - The original matrix to be modified in Level 4, A 
  1592.  2 - The row number to be copied in Level 3, S 
  1593.  3 - The number of times this row is to be copied in 
  1594.      Level 2, G 
  1595.  4 - The row increment to which this row is to be copied 
  1596.      in Level 1, I. This value must be +ve. 
  1597.  
  1598. Eg: INPUT  Level 4 [[ 4 3 6 2] 
  1599.                     [ 1 1 2 1] 
  1600.                     [ 5 1 1 8] 
  1601.                     [ 0 1 3 0] 
  1602.                     [ 3 0 0 0]] 
  1603.  
  1604.            Level 3          1 
  1605.            Level 2          2 
  1606.            Level 1          2 
  1607.  
  1608.    OUTPUT  Level 1 [[ 4 3 6 2] 
  1609.                     [ 1 1 2 1] 
  1610.                     [ 4 3 6 2] 
  1611.                     [ 0 1 3 0] 
  1612.                     [ 4 3 6 2]] 
  1613.  
  1614. It should be noted that the number of rows in the 
  1615. resultant matrix will be the same as for the original so 
  1616. that the following inequality must be satisfied in order 
  1617. to successfully execute the program. 
  1618.  
  1619.        S + G * I  <= Number of Rows in Matrix 
  1620.  
  1621. The restriction on I being positive means that row 
  1622. generation can only proceed downwards, ie higher row 
  1623. numbers cannot be copied to lower ones. 
  1624.  
  1625.  
  1626. SWA 
  1627.  
  1628. This utility is used to swap the first and second columns 
  1629. of a two column matrix. The matrix to be modified is 
  1630. placed in Level 1 of the stack. 
  1631.  
  1632.  
  1633. INTER 
  1634.  
  1635. "INTER" is used to linearly interpolate between X and Y 
  1636. coordinates listed in a 2 column matrix. The matrix of 
  1637. coordinates is in Level 2 and the X value for which an 
  1638. interpolated value of Y is required is placed in Level 1. 
  1639. The program outputs the linearly interpolated value of Y 
  1640. and the row number in the matrix for which the X value 
  1641. immediately proceeds the X value requested. The X 
  1642. coordinates must be in ascending order. 
  1643.  
  1644.  
  1645. Eg:  INPUT  Level 2  [[  1  5 ] 
  1646.                       [  6 12 ] 
  1647.                       [  8  7 ] 
  1648.                       [ 12 13 ]] 
  1649.  
  1650.             Level 1           9 
  1651.  
  1652.    RESULTS  Level 2         8.5 
  1653.             Level 1           4 
  1654.  
  1655.  
  1656. Note:  If the matrix entered in level 2 has more than two 
  1657. columns the excess columns will be ignored by the 
  1658. program. 
  1659.  
  1660.  
  1661. ROTAT 
  1662.  
  1663. This utility performs a coordinate transformation in the 
  1664. X Y plane of a set of coordinates who's X Y values are in 
  1665. the first and second rows respectively of a matrix. The 
  1666. resultant matrix obtained when "ROTAT" is run contains a 
  1667. redefined set of coordinates with respect to a new axis 
  1668. system, x y. 
  1669.  
  1670. The program takes 4 arguments from the stack. These are: 
  1671.  
  1672. Level 4:  Matrix of coordinates to be transformed. 
  1673. Level 3:  X coordinate of origin of new axis system. 
  1674. Level 2:  Y coordinate of origin of new axis system. 
  1675. Level 1:  Angle of rotation in degrees of new axis 
  1676.           system, x y, with respect to original X Y 
  1677.           system. A positive value is a clockwise angle 
  1678.           of rotation of the new axes. 
  1679.  
  1680. The output is a 2 column matrix in stack level 1 which 
  1681. contains the revised set of coordinates with respect to 
  1682. the new axis system. 
  1683.  
  1684.  
  1685. DRLIN 
  1686.  
  1687. "DRLIN" is a utility which draws lines between successive 
  1688. X Y coordinates in a two column matrix. In order to view 
  1689. the image created by "DRLIN" additional commands are 
  1690. required in the relevant programs which use "DRLIN" as a 
  1691. subroutine, for example FREEZE or PVIEW. ( Refer to HP48 
  1692. Owner's Manual for additional information on viewing 
  1693. graphical images ). Scaling of the image also needs to 
  1694. be carried out via additional commands not contained 
  1695. within "DRLIN". 
  1696.  
  1697.  
  1698. INVERT 
  1699.  
  1700. "INVERT" is a stack manipulation utility which 
  1701. supplements stack operations on the HP48. This utility 
  1702. inverts the stack given a number of stack elements to 
  1703. invert in Level 1. 
  1704.  
  1705. Eg:  Level      INPUT     OUTPUT 
  1706.                  
  1707.          6        25           
  1708.          5        33        25 
  1709.          4         6        17 
  1710.          3         2         2 
  1711.          2        17         6 
  1712.          1         4        33 
  1713.                
  1714.  
  1715. COMBIN 
  1716.  
  1717. The "COMBIN" utility combines the columns of 2 matrices 
  1718. in levels 1 and 2 of the stack such that the number of 
  1719. columns in the final matrix equals the sum of the number 
  1720. of columns in the original matrices, and the number of 
  1721. rows remains the same. In other words the matrix 
  1722. dimensions follow the rule: 
  1723.  
  1724. { a b } + { a c } = { a b+c }. 
  1725.  
  1726. The two matrices to be combined must have the same number 
  1727. of rows. 
  1728.  
  1729. Eg:  INPUT    Level 2  [[ 1 7 ]       Level 1 [[ 5 ] 
  1730.                         [ 2 6 ]                [ 8 ] 
  1731.                         [ 3 9 ]                [ 3 ] 
  1732.                         [ 4 5 ]]               [ 2 ]] 
  1733.  
  1734.      OUTPUT   Level 1  [[ 1 7 5 ] 
  1735.                         [ 2 6 8 ] 
  1736.                         [ 3 9 3 ] 
  1737.                         [ 4 5 2 ]] 
  1738.  
  1739.  
  1740. It is also possible to use the "COMBIN" utility to 
  1741. combine the rows of 2 matrices in levels 1 and 2 of the 
  1742. stack. This can be achieved by transposing both of the 
  1743. matrices to be combined prior to using the "COMBIN" 
  1744. program and then transposing the resultant matrix. 
  1745.  
  1746. Eg:  INPUT    Level 2  [[ 1 2 3 4 ]   Level 1 [[ 5 8 3 2 ]] 
  1747.                         [ 7 6 9 5 ]] 
  1748.  
  1749.      After             [[ 1 7 ]               [[ 5 ] 
  1750.      Transposing        [ 2 6 ]                [ 8 ] 
  1751.                         [ 3 9 ]                [ 3 ] 
  1752.                         [ 4 5 ]]               [ 2 ]]  
  1753.  
  1754.      OUTPUT   Level 1  [[ 1 7 5 ] 
  1755.                         [ 2 6 8 ] 
  1756.                         [ 3 9 3 ] 
  1757.                         [ 4 5 2 ]] 
  1758.  
  1759.      After             [[ 1 2 3 4 ] 
  1760.      Transposing        [ 7 6 9 5 ] 
  1761.                         [ 5 8 3 2 ]] 
  1762.  
  1763.  
  1764.  
  1765. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  1766. Joe Muccillo 
  1767. 66 Prospect St 
  1768. Pascoe Vale, 3044 
  1769. Melbourne 
  1770. AUSTRALIA 
  1771. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  1772. @@NTL2       SG 
  1773. (Comp.sources.hp48) 
  1774. Item: 103 by kalb@informatik.uni-erlangen.de 
  1775. Author: [Klaus Kalb] 
  1776.   Subj: ntl2 - Number Theory 
  1777.   Date: Mon May 04 1992 
  1778.  
  1779. [Man, oh man; I wish I had this when I was taking that 
  1780.  Number Theory course at UCI!  -jkh-] 
  1781.  
  1782. NTL2 is a library for the pocket calculator HP48SX to 
  1783. perform basic numbertheoretic calculations. It provides 
  1784. modular arithmetic, factorization of integers, chinese 
  1785. remaindering and some numbertheoretic functions. 
  1786.  
  1787. It is provided as is, without any warranty or assertion 
  1788. of fitness for any purpose. Note that this library makes 
  1789. use of undocumented and unsupported features of the HP48. 
  1790. This might cause data loss or even hardware damage. Use 
  1791. it at your own risk. 
  1792.  
  1793. This software may be distributed freely for noncommercial 
  1794. purposes, as long as this file and the documentation file 
  1795. is distributed with it. You may not make any changes to 
  1796. the software or to the documentation, put it into ROM, 
  1797. publish it in journals or sell it without written 
  1798. permission of the author. 
  1799.  
  1800. Parts of the code in this library were developed by 
  1801. Jurjen N. E. Bos and are included with his kind 
  1802. permission. Thus this library contains a slightly 
  1803. improved version of his `Ultimate Factoring Program'. 
  1804.  
  1805. 21/1/92, -KK 
  1806.         Klaus Kalb 
  1807.         Huettendorfer Weg 14 
  1808.         W-8510 Fuerth 17 
  1809.         Federal Republic of Germany 
  1810.  
  1811.         email: kskalb@informatik.uni-erlangen.de 
  1812.          
  1813.  
  1814. This is the complete documentation of the library NTL2 
  1815. version 2.8. The ID of this library is 1672 and the title 
  1816. reads `NTL2 2.8 Number Theory` 
  1817.  
  1818. The command `AboutNTL2` should display the following screen: 
  1819.  
  1820.         NTL2 2.8 Number Theory 
  1821.         created 04/15/92 00:26 
  1822.         (C) 1991 by Klaus Kalb 
  1823.         Credits to Jurjen Bos 
  1824.  
  1825. and return the version identification string "2.8" to 
  1826. level 1. 
  1827.  
  1828. This library attaches itself automatically to the 
  1829. 'HOME'-directory. Consult your HP48 Owner's Manual for 
  1830. details about libraries. 
  1831.  
  1832. The library uses a reserved variable 'Data.NTL2' to store 
  1833. the currently set modulus and other information. 
  1834. Contents of 'Data.NTL2': 
  1835.  
  1836.     1 : Modulus (as entered) 
  1837.     2 : Modulus (as a binary integer) 
  1838.     3 : Phi(Modulus) 
  1839.     4 : Lambda(Modulus) 
  1840.     5 : Factorization of Modulus 
  1841.     6 : Factorization of Lambda(Modulus) 
  1842.     7 : Splitting for CRA                
  1843.     8 : Data for CRA                  
  1844.     9 : Splitting in Binary              
  1845.  
  1846.  
  1847.  
  1848. íííííííííí THE LIBRARY COMMANDS ííííííííííí 
  1849.  
  1850.  
  1851. AboutNTL2 
  1852.  
  1853.     Displays a screen full of information about NTL2 and 
  1854.     creates a temporary menu to access the various pages 
  1855.     of the NTL2 menu. 
  1856.     The current version ID string "2.8" is returned. 
  1857.     If an entry in the temporary menu is executed with 
  1858.     the string "2.8" in level 1, this string is dropped 
  1859.     and the address of the author is displayed. 
  1860.  
  1861.  
  1862. MSet 
  1863.  
  1864.     Sets the modulus to the argument. All entries in 
  1865.     Data.NTL2 will be destroyed. 
  1866.  
  1867.     If the argument is a list, the entries must be 
  1868.     relatively prime. In this case the modulus will be 
  1869.     set to the product of all entries in the list (if 
  1870.     this number is smaller then 2^63) and the chinese 
  1871.     remainder support will be initialized to the given 
  1872.     factorization. 
  1873.  
  1874.     The modulus determines the representation of 
  1875.     residues: 
  1876.  
  1877.     ---    If it is positive, then the least positive 
  1878.      residues will be used. 
  1879.  
  1880.     ---    If it is negative, then the residue with the 
  1881.      least absolute value will be used. 
  1882.  
  1883.     ---    If its a binary, all residues will be 
  1884.      represented as binaries. 
  1885.  
  1886.     Note that even if the modulus has been set to a real 
  1887.     number, all arithmetic will be performed with 
  1888.     binaries. So be sure that the current wordsize is 
  1889.     large enough. 
  1890.  
  1891.  
  1892. MGet 
  1893.  
  1894.     Retrieves the current modulus. 
  1895.  
  1896.  
  1897. MTgl 
  1898.  
  1899.     If the current modulus is a binary number less or 
  1900.     equal to 10^12, the modulus will be switched to its 
  1901.     negative real value. 
  1902.  
  1903.     If the current modulus is a real number, its sign 
  1904.     will be changed. 
  1905.  
  1906.     This function allows changing the representation 
  1907.     without destroying the values stored in Data.NTL2. 
  1908.  
  1909.  
  1910. MPrg 
  1911.  
  1912.     Purges Data.NTL2 from the current directory. 
  1913.  
  1914.  
  1915.  
  1916. íííííííííí BASIC MODULAR ARITHMETIC ííííííííííí 
  1917.  
  1918. ->Mod 
  1919.  
  1920.     Converts its argument in the current modular 
  1921.     representation Algebraics containing only global and 
  1922.     local names and the basic functions +,-,*,/,INV() and 
  1923.     NEG() will be evaluated. 
  1924.  
  1925.     Any not integral reals will be converted using ->Q. 
  1926.  
  1927.     Note that you have to be very careful about roundoffs 
  1928.     when you apply ->MOD to a non integral real. 
  1929.  
  1930.     If the argument is a list, ->MOD will be applied to 
  1931.     each element of the list and the individual results 
  1932.     will be combined to a new list. 
  1933.  
  1934.     If the argument is a real array or a vector, ->MOD 
  1935.     will be applied to any entry. 
  1936.  
  1937.     stack diagram: 
  1938.         #m                    í  r (binary or real) 
  1939.         m                     í  r (binary or real) 
  1940.         `Formula`             í  r (binary or real) 
  1941.         { o1 o2 ... }         í  { r1 r2 ... } 
  1942.         [ real vector ]       í  [ real vector ] 
  1943.         [ [ real matrix ] ]   í  [ [ real matrix ] ] 
  1944.  
  1945.  
  1946. MAdd 
  1947.  
  1948.     Modular addition. 
  1949.     Supports chinese remainder representation. 
  1950.  
  1951.     stack diagram: 
  1952.        #a #b                   í  a+b (binary or real) 
  1953.        a b                     í  a+b (binary or real) 
  1954.        #a b                    í  a+b (binary or real) 
  1955.        #a #b                   í  a+b (binary or real) 
  1956.        { a_1 ... a_n } b       í  { a+b_1 ... a+b_n } 
  1957.        { a_1 ... a_n } #b      í  { a+b_1 ... a+b_n } 
  1958.        #a { b_1 ... b_n }      í  { a+b_1 ... a+b_n } 
  1959.        a { b_1 ... b_n }       í  { a+b_1 ... a+b_n } 
  1960.        { a_1 ... } { b_1 ... } í  { a+b_1 ... a+b_n } 
  1961.  
  1962.  
  1963. MSub 
  1964.  
  1965.     Modular subtraction. 
  1966.     Supports chinese remainder representation. 
  1967.  
  1968.     stack diagram: 
  1969.         #a #b                   í  a-b (binary or real) 
  1970.         a b                     í  a-b (binary or real) 
  1971.         #a b                    í  a-b (binary or real) 
  1972.         #a #b                   í  a-b (binary or real) 
  1973.         { a_1 ... a_n } b       í  { a-b_1 ... a-b_n } 
  1974.         { a_1 ... a_n } #b      í  { a-b_1 ... a-b_n } 
  1975.         #a { b_1 ... b_n }      í  { a-b_1 ... a-b_n } 
  1976.         a { b_1 ... b_n }       í  { a-b_1 ... a-b_n } 
  1977.         { a_1 ... } { b_1 ... } í  { a-b_1 ... a-b_n } 
  1978.  
  1979.  
  1980. MMul 
  1981.  
  1982.     Modular multiplication. 
  1983.     Supports chinese remainder representation. 
  1984.     Also allows multiplikation of a real vector by a 
  1985.     constant 
  1986.  
  1987.     stack diagram: 
  1988.       #a #b                   í  a*b (binary or real) 
  1989.       a b                     í  a*b (binary or real) 
  1990.       #a b                    í  a*b (binary or real) 
  1991.       #a #b                   í  a*b (binary or real) 
  1992.       { a_1 ... a_n } b       í  { a*b_1 ... a*b_n } 
  1993.       { a_1 ... a_n } #b      í  { a*b_1 ... a*b_n } 
  1994.       #a { b_1 ... b_n }      í  { a*b_1 ... a*b_n } 
  1995.       a { b_1 ... b_n }       í  { a*b_1 ... a*b_n } 
  1996.       { a_1 ... } { b_1 ... } í  { a_1*b_1 ... a_n*b_n } 
  1997.       [ a_1 ... a_2 ] c       í  { c*a_1 ... c*a_n } 
  1998.  
  1999.  
  2000. MDiv 
  2001.  
  2002.     Modular division. 
  2003.     Note that the divisor must be a unit. 
  2004.     Supports chinese remainder representation. 
  2005.     Also allows multiplikation of a real vector by a 
  2006.     constant 
  2007.  
  2008.     Note that it is more efficient to multiply the vector 
  2009.     by the inverse. 
  2010.  
  2011.     stack diagram: 
  2012.        #a #b                   í  a/b (binary or real) 
  2013.        a b                     í  a/b (binary or real) 
  2014.        #a b                    í  a/b (binary or real) 
  2015.        #a #b                   í  a/b (binary or real) 
  2016.        { a_1 ... a_n } b       í  { a/b_1 ... a/b_n } 
  2017.        { a_1 ... a_n } #b      í  { a/b_1 ... a/b_n } 
  2018.        #a { b_1 ... b_n }      í  { a/b_1 ... a/b_n } 
  2019.        a { b_1 ... b_n }       í  { a/b_1 ... a/b_n } 
  2020.        { a_1 ... } { b_1 ... } í  { a/b_1 ... a/b_n } 
  2021.        [ a_1 ... a_2 ] c       í  { a_1/c ... a_n/c } 
  2022.  
  2023.  
  2024. MExp 
  2025.  
  2026.     Modular exponentation. 
  2027.     Accepts negative exponents as well as positive ones. 
  2028.     Supports chinese remainder representation for the 
  2029.     base only. 
  2030.  
  2031.     stack diagram: 
  2032.       #b #e                     í  b^e (binary or real) 
  2033.       b e                       í  b^e (binary or real) 
  2034.       #b e                      í  b^e (binary or real) 
  2035.       b #e                      í  b^e (binary or real) 
  2036.       { b_1 ... b_n }    #e     í  { b^e_1 ... b^e_n } 
  2037.       { b_1 ... b_n }    e      í  { b^e_1 ... b^e_n } 
  2038.  
  2039.  
  2040. MInv 
  2041.  
  2042.     Modular inversion. 
  2043.     Calculates the multplicative inverse of the argument 
  2044.     using an extended GCD algorithm. 
  2045.  
  2046.     Supports chinese remainder representation. 
  2047.  
  2048.     stack diagram: 
  2049.        #m                        í  r (binary or real) 
  2050.        m                         í  r (binary or real) 
  2051.        { m_1 m_2 ... m_n }       í  { r_1 r_2 ... r_n } 
  2052.  
  2053.  
  2054. MNeg 
  2055.  
  2056.     Multiplies its argument with -1. 
  2057.     Supports chinese remainder representation. 
  2058.  
  2059.     stack diagram: 
  2060.        #m                        í  r (binary or real) 
  2061.        m                         í  r (binary or real) 
  2062.        { m_1 m_2 ... m_n }       í  { r_1 r_2 ... r_n } 
  2063.  
  2064.  
  2065.  
  2066. íííííííííí ADVANCED MODULAR ARITHMETIC ííííííííííí 
  2067.  
  2068.  
  2069. Mû 
  2070.  
  2071.     Extracts the square root of its argument (if 
  2072.     possible) 
  2073.  
  2074.     Needs an odd modulus. 
  2075.     This needs the 'standard' chinese remainder setup. 
  2076.  
  2077.     stack diagram: 
  2078.         #x              í  r (binary or real) 
  2079.         x               í  r (binary or real) 
  2080.  
  2081.  
  2082. MSq? 
  2083.  
  2084.     Checks wether its argument is a square modulo the 
  2085.     current modulus. Needs an odd modulus. 
  2086.  
  2087.     stack diagram: 
  2088.         #x              í  0/1 
  2089.         x               í  0/1 
  2090.  
  2091.  
  2092. MOrd 
  2093.     Calculates the order of the given element. 
  2094.      
  2095.     stack diagram: 
  2096.         #x              í  p (binary or real) 
  2097.         x               í  p (binary or real) 
  2098.  
  2099.  
  2100. MNPr 
  2101.  
  2102.     Returns the next primitive element modulo the current 
  2103.     modulus. If there are no primitive elements, an error 
  2104.     will be generated. 
  2105.  
  2106.     stack diagram: 
  2107.         #x              í  p (binary or real) 
  2108.         x               í  p (binary or real) 
  2109.  
  2110.  
  2111. MPr? 
  2112.  
  2113.     Returns 1 if its argument is a primitive element 
  2114.     modulo the current modulus. 
  2115.  
  2116.     stack diagram: 
  2117.         #x              í  0/1 
  2118.         x               í  0/1 
  2119.  
  2120.  
  2121.  
  2122. íííííííííí CHINESE REMAINDER TECHNIQUES ííííííííííí 
  2123.  
  2124.  
  2125. CSet 
  2126.  
  2127.     Sets the chinese remainder mode. 
  2128.     The argument is a list of pairwise relatively prime 
  2129.     integers. Note that binaries and integral reals 
  2130.     (positive and negative) are allowed in the input 
  2131.     list. 
  2132.  
  2133.     If a modulus is set, the product of all numbers in 
  2134.     the list must match the modulus. If not, the modulus 
  2135.     is set to this product as a binary integer if this 
  2136.     product can be represented in 63 bits. 
  2137.  
  2138.     stack diagram: 
  2139.            { r_1 ... }               í  
  2140.  
  2141.  
  2142. CGet 
  2143.  
  2144.     recalls the current chinese remainder setting to the 
  2145.     stack 
  2146.  
  2147.     stack diagram: 
  2148.                         í  { r_1 ... } 
  2149.  
  2150.  
  2151. ->Crm 
  2152.  
  2153.     Converts a number into the current chinese remainder 
  2154.     representation. The result will be a list of residues 
  2155.     according to the call to CSet. If CSet hasn't been 
  2156.     called, the current modulus will be factored and a 
  2157.     default setting will be made up. 
  2158.  
  2159.     stack diagram: 
  2160.         m               í  { r_1 ... } 
  2161.         #m              í  { r_1 ... } 
  2162.  
  2163.  
  2164. Crm-> 
  2165.  
  2166.     Converts from the chineses remainder representation 
  2167.     back to the normal modular representation. 
  2168.  
  2169.     This is done by the well known chinese remainder 
  2170.     algorithm. The input must be a list of real or binary 
  2171.     integers 
  2172.  
  2173.     stack diagram: 
  2174.         { r_1 ... }         í  m (binary or real) 
  2175.  
  2176.  
  2177.  
  2178. íííííííííí BASIC NUMBER THEORY ROUTINES ííííííííííí 
  2179.  
  2180.  
  2181. BGcd 
  2182.  
  2183.     Calculates the greatest common divisor of two 
  2184.     numbers. 
  2185.  
  2186.     This is done by a binary algorithm programmed in ML 
  2187.  
  2188.     stack diagram: 
  2189.         #a #b           í  #d 
  2190.         a b             í  d 
  2191.         #a b            í  #d 
  2192.         a #b            í  #d 
  2193.  
  2194.  
  2195. XGcd 
  2196.  
  2197.     Calculates the greatest common divisor of two numbers 
  2198.     and gives coefficients for a representation of the 
  2199.     gcd as linear combination of the arguments. 
  2200.         gcd(a,b) = d = t*b-s*a with 0<=t<=a and 0<=s<b 
  2201.     Both arguments must be positive. 
  2202.  
  2203.     stack diagram: 
  2204.         #a #b           í  #s #t #d 
  2205.         a b             í  s t d 
  2206.  
  2207.  
  2208. Lcm 
  2209.  
  2210.     Calculates the least common multiple of two numbers. 
  2211.     The result will always be positive. 
  2212.     BUGS: an overflow isn't detected 
  2213.  
  2214.     stack diagram: 
  2215.         #a #b           í  #r 
  2216.         a #b            í  #r 
  2217.         #a b            í  #r 
  2218.         a b             í  r 
  2219.  
  2220.  
  2221.  
  2222. íííííííííí NUMBER THEORY FUNCTIONS ííííííííííí 
  2223.  
  2224. Ntfé 
  2225.  
  2226.     Calculates the Euler totient function. 
  2227.     If the argument is a list, the entries must be in 
  2228.     ascending order. 
  2229.  
  2230.     stack diagram: 
  2231.            #m                    í  #Phi(m) 
  2232.            m                     í  Phi(m) 
  2233.            { p_1 ... p_n }       í  Phi(p_1 * ... * p_n) 
  2234.  
  2235.  
  2236. Ntf\Gl 
  2237.  
  2238.     Calculates the Charmichael's Lambda function 
  2239.     The Charmichael Lambda function gives the exponent of 
  2240.     the group of units modulo m. 
  2241.     If the argument is a list, the entries must be in 
  2242.     ascending order. 
  2243.  
  2244.     stack diagram: 
  2245.         #m                    í  #Lambda(m) 
  2246.         m                     í  Lambda(m) 
  2247.         { p_1 ... p_n }       í  Lambda(p_1 * ... * p_n) 
  2248.  
  2249.  
  2250. Ntfå 
  2251.  
  2252.     Calculates the number of divisors of the argument. 
  2253.     If the argument is a list, the entries must be in 
  2254.     ascending order. 
  2255.  
  2256.     stack diagram: 
  2257.         #m                    í  #Sigma(m) 
  2258.         m                     í  Sigma(m) 
  2259.         { p_1 ... p_n }       í  Sigma(p_1 * ... * p_n) 
  2260.  
  2261.  
  2262. Ntfæ 
  2263.  
  2264.     Calculates the Moebius function 
  2265.     If the argument is a list, the entries must be in 
  2266.     ascending order. 
  2267.  
  2268.     stack diagram: 
  2269.         #m                    í  #Mu(m) 
  2270.         m                     í  Mu(m) 
  2271.         { p_1 ... p_n }       í  Mu(p_1 * ... * p_n) 
  2272.  
  2273.  
  2274. Jacobi 
  2275.  
  2276.     Calculates the Jacobi symbol for its arguments using 
  2277.     the quadratic reciprocity law. Note that the value 
  2278.     is zero if the arguments aren't relatively prime 
  2279.     and that the value in level 1 must be an odd number. 
  2280.     The result will always equal +1, -1 or 0. 
  2281.  
  2282.     stack diagram: 
  2283.       a b             í  (a/b) 
  2284.       #a #b           í  (a/b) 
  2285.       a #b            í  (a/b) 
  2286.       #a b            í  (a/b) 
  2287.  
  2288.  
  2289.  
  2290. íííííííííí PRIMALITY TESTING AND FACTORING ííííííííííí 
  2291.  
  2292. [Note: These four functions are available in a separate 
  2293.  smaller library called FCTR.LIB on Goodies Disk #8. 
  2294.  -jkh-] 
  2295.  
  2296. Prm? 
  2297.  
  2298.     Tests whether its argument is a prime number 
  2299.     Returns 1 if it's a prime, else 0 
  2300.     If the number to test is greater then 25*10^9, the 
  2301.     test may take up to several minutes. 
  2302.     Negative primes are recognized correctly 
  2303.  
  2304.     stack diagram: 
  2305.         #m              í  0/1 
  2306.         m               í  0/1 
  2307.  
  2308.  
  2309. NPrm 
  2310.  
  2311.     Finds the smallest prime greater than the absolute 
  2312.     value of the argument 
  2313.  
  2314.     stack diagram: 
  2315.         #x              í  #p 
  2316.         x               í  p 
  2317.  
  2318.  
  2319. PPrm 
  2320.  
  2321.     Finds the greatest prime less than the absolute value 
  2322.     of the argument 
  2323.  
  2324.     stack diagram: 
  2325.         #x              í  #p 
  2326.         x               í  p 
  2327.  
  2328.  
  2329. Factor 
  2330.  
  2331.     Factors its argument into primes. 
  2332.  
  2333.     The output will be a list containing all prime 
  2334.     divisors (repeated according to their multiplicity) 
  2335.     in ascending order. 
  2336.  
  2337.     The entries in the list will have the same type as 
  2338.     the argument. 
  2339.  
  2340.     The number to be factored must be positive. 
  2341.  
  2342.     stack diagram: 
  2343.            #x      í  { #p_1 #p_2 ... } 
  2344.            x       í  { p_1 p_2 ... } 
  2345.  
  2346.  
  2347.  
  2348. íííííííííí ADDITIONAL MODULUS ARITHMETIC ííííííííííí 
  2349.  
  2350.  
  2351. MRand 
  2352.  
  2353.     Generates a random number modulo the current modulus. 
  2354.  
  2355.     stack diagram: 
  2356.         í  r (binary or real) 
  2357.  
  2358.  
  2359.  
  2360. íííííííííí MENU HANDLING ííííííííííí 
  2361.  
  2362.  
  2363. MenuNTL2 
  2364.  
  2365.     Displays a temporary menu to access the various pages 
  2366.     of the NTL2 library menu. This gives access to NTL2 
  2367.     similar to the built-in menu keys like MTH. 
  2368. @@PFIT       SG 
  2369.           Éíííííííííííííííííííííííííííííííííííí» 
  2370.           º POLYNOMIAL CURVE FITTING REVISITED º 
  2371.           º         by Joseph K. Horn          º 
  2372.           èíííííííííííííííííííííííííííííííííííí¼ 
  2373.  
  2374. Included as an example program in Jim Donnelly's book, 
  2375. "The HP 48 Handbook, 2nd Edition" (pg. 83-85). 
  2376.  
  2377. [Note: This is a mathematically-exact fit program, not a 
  2378.  statistical "best fit". For statistical work, see 
  2379.  CUFIT. -jkh-] 
  2380.  
  2381. David Kurtz's 'POLYFIT' program on Goodies Disk #6 is 
  2382. 2,256 bytes long, and takes 1.5 hours to fit 15 data 
  2383. points to a polynomial exactly (not by least-squares 
  2384. approximation). Here's a program that does the same 
  2385. task, but with better accuracy, in 197 bytes, in 28 
  2386. seconds!  And what's really cool, there is another 
  2387. program included here that does a pseudo scatter plot 
  2388. with large, easily visible points, and then, on top of 
  2389. that, plots the polynomial that fits those points, with 
  2390. labeled axes. 
  2391.  
  2392. The 'PFIT' program takes the points' coordinates as its 
  2393. input (in matrix form), and gives back the coefficients 
  2394. of the polynomial as its output (in array form). 
  2395.  
  2396. The 'SHOP' program also takes the points' coordinates as 
  2397. its input, but does a kind of scatter plot (using arrow 
  2398. grobs instead of single pixels), and then connects the 
  2399. points with the polynomial generated by PFIT. Note: SHOP 
  2400. creates then purges 'äDAT', 'PPAR', and 'EQ' in the 
  2401. current directory. 
  2402.  
  2403. 'PFIT' EXAMPLE: What polynomial passes through (-2,-3), 
  2404. (0,7), (1,6), and (2,9)? 
  2405.  
  2406. METHOD: Press P1 and see the proper input for this 
  2407. example: 
  2408.  
  2409.         [[ -2 -3 ] 
  2410.          [  0  7 ] 
  2411.          [  1  6 ] 
  2412.          [  2  9 ]] 
  2413.  
  2414. Then run PFIT (Polynomial Fit). See: 
  2415.  
  2416.         [ 1 -1 -1 7 ] 
  2417.  
  2418. These are the coefficients of the polynomial answer; thus 
  2419. x^3-x^2-x+7=0 passes through those points. 
  2420.  
  2421. Note: Leading zeros (or leading values very close to 
  2422. zero) mean that you supplied more points than necessary. 
  2423. Ignore them. 
  2424.  
  2425. 'SHOP' EXAMPLE: What do those points and that polynomial 
  2426. LOOK like? 
  2427.  
  2428. METHOD: Press P1, then run SHOP (Show Polynomial). See 
  2429. the points, then the polynomial, and then labeled axes 
  2430. get displayed. Press ON to exit graphics mode, or press 
  2431. GRAPH (PICTURE on the G/GX) to exit scrolling mode. 
  2432.  
  2433. 'P2' is another sample input. Try it with PFIT and SHOP. 
  2434. @@POLY46SX   S- 
  2435. BEGIN_DOC_POLY_version_4.6sx 
  2436.  
  2437.                                  Gothenburg, October 1993 
  2438.  
  2439. Hello everybody! 
  2440.  
  2441.  
  2442. Preludium to the former preludium : 
  2443. ííííííííííííííííííííííííííííííííííí 
  2444.  
  2445. I was wrong !  Here's yet another version ... but it's 
  2446. well worth it ;-) Please, re-read this document, because 
  2447. new features are implemented !! Of course, now, the 
  2448. possibilities of making yet another version are 
  2449. extremelly small, since I don't have the '48 anymore ... 
  2450. :-( 
  2451.  
  2452. Preludium to this last version ever (coming from me) : 
  2453. íííííííííííííííííííííííííííííííííííííííííííííííííííííí 
  2454. (that was v4.4 ...:) 
  2455.  
  2456. From the beginnig, I wanted to make a short and fast 
  2457. Libarary to deal with polynoms. I did several versions, 
  2458. and versions 3.3 & 3.5 were quite stable, so they were 
  2459. released to the net. Then I had the need of developing 
  2460. the product to have the biggest posible degree of 
  2461. accuracy in the market, without loosing speed. Versions 
  2462. 4.x were released to the net. Stable, I had thought, 
  2463. until I got lots of letters containg all from bug-reports 
  2464. to whishes of new features, etc. Now from all the 
  2465. enormous response this library has had among its users, I 
  2466. could develop this package into a very stable version - 
  2467. the last reports were about small things ...  It was you 
  2468. as a user who helped me and I thank you very much for 
  2469. that. Also, you got yourself a better program now. And 
  2470. how about the initial objectives ? Well, the lib sure has 
  2471. grown a lot, but that's the only way of trapping more & 
  2472. more weird cases, and thus, making it as safe as 
  2473. possible. [...more stuff deleted...] 
  2474.  
  2475. Changes with respect to version 4.2 : 
  2476. ííííííííííííííííííííííííííííííííííííí 
  2477.  
  2478. 1) A reported bug from versions 4.X was corrected - a 
  2479.    comma was missing in an internal Long Real, so for 
  2480.    some impredictable polynoms it would ask you to 
  2481.    "Please, report a bug!", and for others it would run 
  2482.    forever . 
  2483.  
  2484. 2) Acording to many letters wanting some changes in the 
  2485.    output of the PDIV and PFACT, they now have a 
  2486.    different way of presenting the results, just to make 
  2487.    it easy for you to use those routines from a program. 
  2488.  
  2489. 3) Other bugs non-reported were fixed as well, like the 
  2490. [1] { ... } PF, etc 
  2491.  
  2492.  
  2493. Changes with respect to version 4.4 : 
  2494. ííííííííííííííííííííííííííííííííííííí 
  2495.  
  2496. 1) The biggest change for you as a user: PF has become 
  2497.    really user-friendly! Now it's perharps the most 
  2498.    complete Partial Fraction Decomposition program in the 
  2499.    market !! (see the doc about that) 
  2500.  
  2501. 2) The biggest change for you who like to compare 
  2502.    execution times: thanks to new Assembly routines in 
  2503.    vital places, the speed of some routines (like ROOTS) 
  2504.    has almost doubled !! (see the thanks part about that) 
  2505.  
  2506. 3) PDIV, PMULT, PADD and RDER won't error with 'zero 
  2507.    polynoms' anymore ... (see the error part of the doc) 
  2508.  
  2509. Changes with respect to version 4.5 : 
  2510. ííííííííííííííííííííííííííííííííííííí 
  2511.  
  2512. 1) A bug that *everybody* reported in PF is fixed. Also, 
  2513.    the function is improved. Re-read that part of the 
  2514.    manual. 
  2515.  
  2516. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  2517. Copyright (c) 1993  Carlos Ferraro except : 
  2518.  
  2519. L%SQRT.asm    Kindly donated by Mario Mikocevic & Mika 
  2520. Heiskanen 
  2521.  
  2522. L%FLEVAL.asm  Kindly donated by Mika Heiskanen 
  2523.  
  2524. All Rights Reserved 
  2525.  
  2526.  
  2527. DISCLAIM : 
  2528.  
  2529. POLY 4.6sx and this manual are presented as is, without 
  2530. warranties, expressed or implied. The author makes no 
  2531. guarantee as to the fitness of this software. 
  2532.  
  2533. POLY 4.6sx can be copied freely,  provided the software, 
  2534. including this manual, is copied in its entirety. The 
  2535. user cannot be charged, in whole or in part, except for 
  2536. the cost of reproduction. No part of this package may be 
  2537. used for commercial purposes without written permission 
  2538. from the author. 
  2539.  
  2540. POLY 4.6sx uses a lot of unsupported entries, but it's 
  2541. tested succesfully in versions E and J . If you have 
  2542. lower versions, you'd better back up everything before 
  2543. trying it. If you find bugs or possible missbehavings 
  2544. please let me know at once . 
  2545.  
  2546. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  2547.  
  2548. This is a very fast library (full sys-rpl & assembly !) 
  2549. to deal with the fundamental polynom necessities: 
  2550.  
  2551.    ROOTS (all roots of polynom) 
  2552.    PDIV (polynom synthetic division) 
  2553.    PMULT (polynom multiplication)  
  2554.    PADD (polynom addition) 
  2555.    PEVAL (polynom evaluation at a point) 
  2556.    PDER (polynom derivation) 
  2557.    PF (partial fraction decomposition) 
  2558.    R->P (polynom builder - having the roots) 
  2559.    PFACT (polynom primitive factors) 
  2560.    ALG-> (algebraic to polynom) 
  2561.    ->AP (the opposite of above) 
  2562.  
  2563. IMPORTANT : Unlike other polynom utilities I use vectors 
  2564. instead of lists to represent polynoms. This is only done 
  2565. for ensuring total control of the types of the 
  2566. input-elements, since the internal representation of the 
  2567. polynoms are lists of L% (this means Long 
  2568. Reals/Complexes). 
  2569.  
  2570. For those who aren't familiar with non-symbolic polynom 
  2571. representation: 
  2572.  
  2573. Example: 
  2574.  
  2575. x^4 + 2*x^3 - 4*x = [ 1 2 0 -4 0 ] 
  2576.  
  2577. Example: 
  2578.  
  2579. 7*x^3 - 5*x^2*i + 3 + 2*i = [ (7,0) (0,-5) (0,0) (3,2) ] 
  2580.  
  2581. All functions perform automatic deflation of leading 
  2582. zeros in the representation. 
  2583.  
  2584. Error Messages : 
  2585. íííííííííííííííí 
  2586.  
  2587. 1) In case you do find some weird polynom that makes 
  2588.    ROOTS crash, it will ask you to "Please report a bug!" 
  2589.    This should be quite difficult with this version 
  2590.    thouh, due to many more testing of all kinds of weird 
  2591.    cases, as well as a totally new, sofisticated method 
  2592.    for initializing the numerical computations... 
  2593.  
  2594. 2) In case you do put 2 polynoms lineraly dependent as 
  2595.    argument for RDER it will tell you that it's a 
  2596.    "Constant Rational" 
  2597.  
  2598. 3) In case you input an algebraic which can't be 
  2599.    converted into a polynom using the McLauring series, 
  2600.    as an argument for ALG-> , it will say exactly where 
  2601.    in the calculations the error occurred. It often 
  2602.    happends if the algebraic or its derivatives are not 
  2603.    defined at x=0 
  2604.  
  2605. 4) ROOTS will complain with any (deflated) polynom of 
  2606.    degree less than one - because that's nothing else 
  2607.    than a constant! 
  2608.  
  2609. 5) In case you input a list containing not ONLY Long 
  2610.    Reals OR Long Complexes as argument for ROOTS it will 
  2611.    error with "Bad Argument Type" 
  2612.  
  2613. 6) In case you imput a polynom as denominator for PF, 
  2614.    which contains one multiple 2nd degree primitive, 
  2615.    it'll error with "Case Not Allowed Yet" The algoritm 
  2616.    simply isn't defined for those cases. If somebody 
  2617.    sends me a better algoritm, that'll be reason enough 
  2618.    to release a new version ;) 
  2619.  
  2620.  
  2621. The programs : 
  2622. íííííííííííííí 
  2623.  
  2624. 1) ROOTS  
  2625. takes all the roots (real or complex) of real or complex 
  2626. polynoms. For polynoms of degree 1 & 2, it uses the 
  2627. corresponding algebraic formulas. For degree 3 and above, 
  2628. it uses Laguerres method to come close to the root, and 
  2629. then a variation of Newtons method using the 2nd 
  2630. derivative as well, for quick and safe convergence to the 
  2631. root. A trial to round every element of the resulting 
  2632. polynoms, as well as every root - taking the real and 
  2633. imaginary parts of the complex numbers separatelly - is 
  2634. made. If a complex root is found to have a (rounded) 
  2635. imaginary part equal zero, it will be simply displayed as 
  2636. a real ! Yet, this could be undesired when looking for 
  2637. roots known to be close to (but not exact) integers. 
  2638. (example: (x + 000.1)^3 ) Simply set UserFlag 4 and no 
  2639. rounding will be performed at any stage of the 
  2640. calculations. 
  2641.  
  2642. ROOTS is both faster and more accurate than before - at 
  2643. least one decimal more accurate - 10 decimals accuracy is 
  2644. what you get for sure. 
  2645.  
  2646. NOTE !  A new feature in ROOTS : It accepts { L% } - but 
  2647.         not { F% } ( it controls so that all elements are 
  2648.         either all %% or all C%% :) - and it takes the 
  2649.         roots of a polynom represented that way ! This is 
  2650.         specially interesting after having used the 
  2651.         hidden features, like multiplication, etc, to get 
  2652.         the roots with a higher degree of accuracy than 
  2653.         usual. Observe that the answer is { L% } in this 
  2654.         case ! 
  2655.  
  2656. Input: 
  2657. 1: [poly] or {poly_L%} 
  2658. Output: 
  2659. 1: {roots} or {roots_L%%} 
  2660.  
  2661. EXAMPLE: Taking the roots of [ 4 33 68 15 ] : 
  2662. the answer { -3 -5 -.25 } 
  2663. comes in ~ 0.87 seconds - faster than PROOT 
  2664.  
  2665. EXAMPLE: Taking the roots of [ 1 3 2 -1 -3 -2 ]  gives  
  2666. the answer { 1 
  2667.            (-.5 , -.866025403783) 
  2668.            (-.5 , .866025403783) 
  2669.            -2 -1 } 
  2670.            in ~ 3.5 seconds - faster than PROOT 
  2671.  
  2672. EXAMPLE: Taking the roots of [ (4,0) (33,1) (76,5) (57,0) 
  2673. (10,0) ] gives the answer 
  2674.   
  2675. { (-2,10855823443;-,490913020551)  
  2676. -5 
  2677. (-,892806137173;,252602578667) 
  2678. (-,248635628397;-1,16895581159E-2) 
  2679. after ~  6.5 seconds 
  2680. Observe that the coeffitients of the polynom are complex! 
  2681.  
  2682. EXAMPLE: Taking the roots of [ 1 21 183 847 2196 3024 
  2683. 1728 ] : 
  2684.  
  2685. the answer { -4 -4 -4 -3 -3 -3 } 
  2686.  
  2687. comes in  ~ 3.3 seconds - much faster than PROOT 
  2688.  
  2689. EXAMPLE: Taking the roots of [ 1 1.533333333333 -3.15 
  2690. -1.933333333333 -.25 ] : 
  2691.  
  2692. the answer { 1.5 -2.5 -.3333333333333 -.2  } 
  2693.  
  2694. comes in  ~ 2.0 seconds 
  2695.  
  2696. 2) PDIV - synthetic polynom division, or dividing a 
  2697. polynom by a number. 
  2698.  
  2699. Input: 
  2700. 2: [poly] 
  2701. 1: [poly] or % (that is, a real) or C% (that is, a 
  2702. complex) 
  2703.  
  2704. It will now ALWAYS return the rest at level 2 , just to 
  2705. make it easier for you to use this routine in an own 
  2706. program ! 
  2707.  
  2708. Output: 
  2709. 2: [resting poly]  
  2710. 1: [poly] 
  2711.  
  2712. 3) PMULT - multiplication of 2 polynoms 
  2713. Input: 
  2714. 2: [poly] 
  2715. 1: [poly] 
  2716. Output: 
  2717. 1: [poly] 
  2718.  
  2719. 4) PADD - guess what ... 
  2720. Input: 
  2721. 2: [poly] 
  2722. 1: [poly] 
  2723. Output: 
  2724. 1: [poly] 
  2725.  
  2726. 5) PEVAL - evaluation of a polynom at a point (horner's 
  2727. scheme) 
  2728.  
  2729. Input: 
  2730. 2: [poly] 
  2731. 1: % or C% 
  2732. Output: 
  2733. 1: % or C% 
  2734.  
  2735. 6) PDER - derivation of a polynom 
  2736. Input: 
  2737. 1: [poly] 
  2738. Output: 
  2739. 1: [poly] 
  2740.  
  2741. 7) PF - Partial Fractions expansion Now it supports 2nd 
  2742.         degree forms in the denominator, except for the 
  2743.         case named in the Error part. It supports 2 
  2744.         different ways of input : as before, with output 
  2745.         as before, or simply the rational polynom as 
  2746.         you'd represent it for RDER. That is : 
  2747.  
  2748. Input  (modified "old way"): 
  2749. 2: [poly]              (the polynom corresponding to the 
  2750.                         nominator!) 
  2751.  
  2752. 1: { list of roots }   (roots of the polynom 
  2753.                         corresponding to the denominator!) 
  2754.  
  2755. Output (old way): 
  2756. 2: { sorted list of roots }  ( now sorted in ascending 
  2757.                                order , C% last ) 
  2758.  
  2759. 1: { list of coefficients of the expansion, in order with 
  2760.      the roots} 
  2761.  
  2762. OR 
  2763.  
  2764. Input  (new way): 
  2765. 2: [poly] 
  2766. 1: [poly] 
  2767. Output (new way): 
  2768. 3:   ...         ( ... = all the necessary stack levels) 
  2769. 2: { ob [poly] } 
  2770. 1: { ob [poly] } (where ob is either a real or a polynom) 
  2771.  
  2772. Where ob means the nominator, which can be a real or a 
  2773. polynom, and [poly] means the denominator resulting from 
  2774. the Partial Fraction decomposition of the rational 
  2775. polynom ! 
  2776.  
  2777. IMPORTANT: the order in which the lists appear in the 
  2778.            stack is significant for the multiple terms ! 
  2779.            That is, whenever you see 2 or more equal 
  2780.            terms in the denominator, the 1st means the 
  2781.            lineal term, the 2nd means the quadratic term, 
  2782.            etc, etc. Still don't get it ? Watch the 
  2783.            examples below and review you Calculus books 
  2784.            ... ;-) And the same is for the order of the 
  2785.            elements of the list in case you use the old 
  2786.            way! I've heard some Electrical Engineers 
  2787.            prefer the old way of inputting because of 
  2788.            some of their formulas (?) Simply hit EVAL 
  2789.            when you see the list, and the order of the 
  2790.            elements in the stack has the same 
  2791.            significance as for the new way. 
  2792.  
  2793. NEW FEATURES: When imputing like the 'old way' , the 
  2794.               elements in the list are automatically 
  2795.               sorted in increasing order for the real 
  2796.               elements, and the same for complex 
  2797.               elements. No sort is needed between real 
  2798.               and complex elements, so these ones come 
  2799.               last always. So, for your convenience, I 
  2800.               put the sorted list at level 2, so that you 
  2801.               can see the correct correspondance between 
  2802.               the roots and their coeffitients. 
  2803.            
  2804. EXAMPLES of the new way : 
  2805. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  2806.  
  2807. Input: 
  2808. 2: [1] 
  2809. 1: [1 2 2 2 1] 
  2810.  
  2811. Output:                (After 4.27 seconds) 
  2812.  
  2813. 3: { [-.5 0] [1 0 1] } 
  2814. 2: { .5 [ 1 1] }     ( [1 1] representing now (x+1)^2 ) 
  2815. 1: { .5 [ 1 1] }     ( [1 1] representing simply (x+1) ) 
  2816.  
  2817. And so that means that : 
  2818. '1/(x^4+2*x^2+2*x^2+2*x+1)'  = 
  2819. '1/(2*(x+1))+1/(2*(x+1)^2)-x/(x^2+1)' 
  2820.  
  2821. Input: 
  2822. 2: [1 -2 2] 
  2823. 1: [1 -3 2 0] 
  2824.  
  2825. Output:                (After 1 second) 
  2826.  
  2827. 3: { 1 [1 0] } 
  2828. 2: { -1 [ 1 -1] } 
  2829. 1: { 1 [ 1 -2] } 
  2830.  
  2831. And so that means that : 
  2832. '(x^2-2*x+2)/(x^3-3*x^2+2*x)' = '1/(x-2)-1/(x-1)+1/x' 
  2833.  
  2834. Input: 
  2835. 2: [1] 
  2836. 1: [1 0 0 1] 
  2837.  
  2838. Output:                (After 3 seconds) 
  2839.  
  2840. 2: { [-.3333333333 .66666666666] [ 1 -1 1] } 
  2841. 1: { .3333333333 [ 1 1] } 
  2842.  
  2843. And so that means that : 
  2844. '1/(x^3+1)' = '1/(3*(x+1))-(x-2)/(3*(x^2-x+1))' 
  2845.  
  2846. EXAMPLE of the old way : 
  2847. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  2848.  
  2849. 2: [1 5] 
  2850. 1: [1 -6 11 -6]   ROOTS  í   { 2 1 3 } 
  2851. So that the input is : 
  2852. 2: [1 5] 
  2853. 1: { 2 1 3 }            ( the roots list ) 
  2854. Output: 
  2855. 2: { 1 2 3 }            ( the roots list, now sorted ) 
  2856. 1: { 3 -7 4 } 
  2857. And so that means that : 
  2858. '(x+5)/(x^3-6*x^2+11*x-6)'  = '3/(x-1)-7/(x-2)+4/(x-3)' 
  2859.  
  2860.  
  2861. 8) R->P - Roots into Polynom, actually the invers of 
  2862. ROOTS 
  2863.  
  2864. Input: 
  2865. 1: {list of roots} 
  2866. Output: 
  2867. 1: [poly] 
  2868.  
  2869. 9) PFACT - Polynom FACTorization in primitive polynoms - 
  2870.      that is, in linear polynoms, or in polynoms of 2nd 
  2871.      degree having only complex roots.. 
  2872.  
  2873. Input: 
  2874. 1: [poly] 
  2875. Output: 
  2876. 1: { [poly] ... [poly] }  
  2877.  
  2878. Meaning that if the polynom is factorizable, the 
  2879. resulting primitives will now be placed in a list, just 
  2880. to make it easier for you to use this routine in an own 
  2881. program ! 
  2882.  
  2883. EXAMPLE: 
  2884. Input: 
  2885. 1: [ 1 -6 11 -6 ] 
  2886. Output:               ( In 0.8 seconds ) 
  2887. 1: { [ 1 -1 ] [1 -2 ] [ 1 -3 ] } 
  2888.  
  2889. 10) RDER - Rational DERivation, that is, derivation of a 
  2890.            rational polynom. Note: see the error part of 
  2891.            the document. 
  2892.  
  2893. Input: 
  2894. 2: [poly] 
  2895. 1: [poly] 
  2896. Output: 
  2897. 2: [poly] 
  2898. 1: [poly] 
  2899.  
  2900. EXAMPLE: 
  2901. Input: 
  2902. 2: [ 1 -2 ] 
  2903. 1: [ 1 -3 ] 
  2904. Output:              ( In 0.4 seconds ) 
  2905. 2: [ -1 ] 
  2906. 1: [ 1 -6 9 ] 
  2907.  
  2908. 11) ALG->   - Algebraic polynom/function into one 
  2909.               polynom-vector-representation (may be slow 
  2910.               for compicated algebraic expressions) Uses 
  2911.               McLaurin expansion, so not everything will 
  2912.               be possible to convert into a polynom, for 
  2913.               example, non-analytical functions at origo 
  2914.               will error! (see Error part of the document 
  2915.               ! ) Note: Flag -3 is only temporaly cleared 
  2916.               if set, but left unchaged !! 
  2917.  
  2918. Input: 
  2919. 3: algebraic poly 
  2920. 2: the bounded variable 
  2921. 1: an integer = the degree of the polynom   
  2922.   (this number may be higher than necessary if the 
  2923.   algebraic is a polynom) 
  2924.  
  2925. Output: 
  2926. 1: [poly]     ( deflated of leading zeros if possible ) 
  2927.  
  2928. EXAMPLE: 
  2929. Input: 
  2930. 3: 'Y-1' 
  2931. 2: 'Y' 
  2932. 1: 1 
  2933. Output:        ( In 0.39 seconds ) 
  2934. 1: [ 1 -1 ] 
  2935.  
  2936. 12) ->AP  -  polynom into Algebraic Polynom 
  2937.              Note: Flag -3 is only temporaly cleared if 
  2938.              set, but left unchaged !! 
  2939.  
  2940.              Note2: The variable 'X' is purged if it 
  2941.              contains anything !! 
  2942.  
  2943. Input: 
  2944. 1: [poly] 
  2945. Output: 
  2946. 1: algebraic poly in the variable 'X' . 
  2947.  
  2948. advanced_users-advanced_users-advanced_users-advanced_use 
  2949. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  2950.  
  2951. The commands described below are invisible but typeable - 
  2952. that is, you can't see them in the menu, but you can use 
  2953. them by writting their name. Why did I do so ?! There's 
  2954. one very special reason : those commands are very usefull 
  2955. for the more advanced user, wanting to perform i.e. a 
  2956. series of multiplications *without* loosing the accuracy 
  2957. that transforming the internal representation of the 
  2958. polynoms back-and-forth into real vectors causes, nor 
  2959. loosing any speed ! The ideal cases are multiplication or 
  2960. division of polynoms containing very big or small 
  2961. numbers. Be aware of the following : 
  2962.  
  2963. NO ERROR CHECKING IS PERFORMED IN THESE INTERNAL 
  2964. ROUTINES. USE THEM WITH CARE OR THEY'LL BLOW OUT YOUR 
  2965. MEMORY !!! 
  2966.  
  2967. No stripping of leading zeros is done automatically by 
  2968. these functions ! Remember, they're only released as 
  2969. *extra* features, the package itself is safe and contains 
  2970. already all you need ;-) 
  2971.  
  2972.  
  2973. 13) A->FL - Array [ F% ] to (long-)Floating-point List { 
  2974. L% } 
  2975.  
  2976. 14) FL->A - (long-)Floating-point List - { L% } List to 
  2977. Array [ F% ] 
  2978.  
  2979. 15) FL-L - (long-)Floating-point List { L% } to List (of 
  2980. normal floats) { F% } 
  2981.                    
  2982. 16) FLDIV - Division of a { L% } by { L% } . Returns { L% 
  2983.             } at level 1 & 2 . 
  2984.  
  2985. 17) FLMUL - Multiplication of a { L% } by { L% } 
  2986.  
  2987. 18) FLADD - Addition of a { L% } with a { L% } 
  2988.  
  2989. 19) FLPF  - Partial Fraction of { L% } and { L% } . Note: 
  2990.             level 2 represents poly, level 1 represents 
  2991.             list of roots ! 
  2992.  
  2993. 20) R->FL -  (  { L% } í  { L% }  ) (roots to polynom) 
  2994.  
  2995. 21) FLRDER - Rational derivative of { L% } { L% }  
  2996.  
  2997. 22) FLFACT - Factorizing { L% } . 
  2998.              Note; input demands a NULL{} at level 2 ! 
  2999.              Returns list of all the factors as { { L% } 
  3000.              ...{ L% } } . 
  3001.  
  3002. 23) MULEL  - Multiplication of a { L% } by a L% . 
  3003.              Note: Input 2: L% 
  3004.                          1: { L% }   !! 
  3005.                    Output: the elements in the stack  !! 
  3006.  
  3007. 24) DIVEL - Division of a { L% } by a L% . Note: input 
  3008.             and output as MULEL  !! 
  3009.  
  3010. 25) STRIP0 - Strip all leading 0 (zeros) of a { B% } , 
  3011.              that is both { F% } or { L% } Note: the last 
  3012.              letter of the name is a zero ! 
  3013.  
  3014. ROMPTR 4C8 19 (L%%SQRT) is pure assembly for taking the 
  3015.               roots of a L% Developed by Mario & Mika 
  3016.  
  3017. ROMPTR 4C8 24 (L%FLEVAL ) is pure assembly for evaluating 
  3018.               a { L% } at L% Developed by Mika 
  3019.  
  3020.  
  3021. FOR YOU WHO AREN'T USED TO LIBRARIES : 
  3022. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  3023.  
  3024. INSTRUCTIONS FOR DOWNLOADING: 
  3025. 1) send POLY4_6.LIB (change name if you have comma as 
  3026. radix !) to the 48 (binary mode) 
  3027. 2) call the contents of POLYLIB to the stack 
  3028. 3) purge  POLY4_6.LIB  (optional) 
  3029. 4) enter 0 or 1 or 2 (corresponding to the desired port) 
  3030. and hit STO 
  3031. 5) turn the calculator OFF 
  3032. 6) turn the calculator ON 
  3033.  
  3034. The library is now installed ! 
  3035. If (3) wasn't done, do it now (to save bytes) 
  3036.  
  3037. INSTRUCCIONS TO PURGE THE LIBRARIES: 
  3038. Althought I can't imagine why anybody would like to purge 
  3039. this beauty, here it is: 
  3040. :&:1224 DUP DETACH PURGE 
  3041. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 
  3042.  
  3043. Once the lib is installed, the values are : 
  3044. Library POLY , LID 1224 ,  bytes 5422.5 , cheksum #239Ah . 
  3045. (Observe that this values are from taking "bytes" when 
  3046. the stack shows : Library 1224 : POLY ) 
  3047.  
  3048. This package has been almost entirelly written on the 48 
  3049. itself, using: 
  3050.  
  3051. From Detlef Mueller and Raymond Hellstern : <-RPL-> 4.2 , 
  3052. <-LIB-> 1.8 
  3053.  
  3054. From Detlef Mueller : Several utilities 
  3055.  
  3056. From Mika Heiskanen : SDBG 1.0b, MKROM 1.0b, SADHP 1.05g 
  3057. (this one on Unix :) 
  3058.  
  3059. From Fatri & me : StringWriter 3.12 
  3060.  
  3061. Many thanks to ... 
  3062. íííííííííííííííííí 
  3063.  
  3064. ... Detlef Mueller for his friendship, for the skeleton 
  3065.     of the abs-lib (not used yet), for opinions, tricks, 
  3066.     etc 
  3067.  
  3068. ... Mika Heiskanen for %%RND, L%SQRT and L%FLEVAL in 
  3069.     Assembly, his outstanding on-line-service for his 
  3070.     programs, as well as for many suggestions about L%, 
  3071.     tricks, etc 
  3072.  
  3073. ... Mario Mikocevic for L%SQRT in Assembly 
  3074.  
  3075. ... Peter Larsson from whom I borrowed a HP48SX for 
  3076.     almost a week so that I could develop this last 
  3077.     version 4.6 and the GX versions of my other libs 
  3078.  
  3079. ... Joe Horn for the kernel of the sorting algorithms I 
  3080.     use in this version 
  3081.  
  3082. ... everybody - more than I ever expected ! - who sent me 
  3083.     a mail of appreciation for POLY 3.xx and POLY 4.xx 
  3084.  
  3085. ... everybody who reported bugs in all versions, as well 
  3086.     as all of you who asked for little improvements here 
  3087.     and there, even when I read your mail *after* having 
  3088.     produced those versions ... :) 
  3089.  
  3090. Any questions? Feel free to mail me! 
  3091.  
  3092. úÄÄÄÄ carlos@dd.chalmers.se ÄÄÄÄÄ Computer Logics ÄÄÄÄÄÄ¿ 
  3093. 3                                                       3 
  3094. 3 Address:                            Phone:            3 
  3095. 3 Carlos Ferraro                      (+46 31) 7750549  3 
  3096. 3 Godhemsgatan 60 A                                     3 
  3097. 3 414 68 Gothenburg                        o o          3 
  3098. 3 SWEDEN                                  \___/         3 
  3099. 3                                                       3 
  3100. àÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄù 
  3101. @@QRAD       SG 
  3102. QRAD, Quotient of RADicals, by Joe Horn. 
  3103. Uses SSQR. See SSQR for full documentation. 
  3104. @@SSQR       SG 
  3105. SSQR (Simplified SQuare Root) and 
  3106. QRAD (Quotient of RADicals) 
  3107.      by Joseph K. Horn 
  3108.  
  3109.                          Éíííííí» 
  3110.                          º SSQR º 
  3111.                          èíííííí¼ 
  3112.  
  3113. shecters@ucunix.san.uc.edu [Robb Shecter] writes: 
  3114.  
  3115. > Does anyone know of an algorithm to simplify something 
  3116. > like û128 and get 8*û2 as the result? 
  3117.  
  3118. The following 'SSQR' program requires the FCTR library by 
  3119. Klaus Kalb, which is totally awesome and should be in 
  3120. every HP48 (it works in HP48 version A-P). It's the 
  3121. fastest 48 factorizer in the world. It's available on 
  3122. Goodies Disk #8. 
  3123.  
  3124. INSTRUCTIONS: To get the simplified square root of N, 
  3125. type N (not its square root) and press SSQR ("Simplified 
  3126. SQuare Root"). 
  3127.  
  3128. EXAMPLES: 
  3129.  
  3130.    128 SSQR  í   '8*û2' (Robb's example) 
  3131. 123456 SSQR  í   '8*û1929' in .6 sec (on a 48G) 
  3132.     22 SSQR  í   'û22' (composite but no square factor) 
  3133.     23 SSQR  í   'û23' (prime) 
  3134.     24 SSQR  í   '2*û6' (composite with square factor) 
  3135.     25 SSQR  í   5 (perfect square) 
  3136.  
  3137.                          Éíííííí» 
  3138.                          º QRAD º 
  3139.                          èíííííí¼ 
  3140.  
  3141. Related to this is the problem of turning a decimal 
  3142. number into a ratio of square roots and/or integers. The 
  3143. following 'QRAD' program calls 'SSQR' and therefore 
  3144. requires the FCTR library and automatically simplifies. 
  3145.  
  3146. INSTRUCTIONS: To turn an unrecognizable decimal (or 
  3147. unsimplified algebraic ratio) into a simplified ratio of 
  3148. square roots, run QRAD ("Quotient of RADicals"). Returns 
  3149. good results if the input is a ratio of roots, or a ratio 
  3150. of a root and an integer, or a ratio of integers. 
  3151.  
  3152. EXAMPLES: 
  3153.  
  3154. .217005559243 QRAD  í   'û17/19' (radical/integer) 
  3155. .945905302928 QRAD  í   'û17/û19' (radical/radical) 
  3156. 3.9000674758  QRAD  í   '17/û19' (integer/radical) 
  3157. .894736842105 QRAD  í   '17/19' (integer/integer) 
  3158. 11.313708499  QRAD  í   '8*û2'  (Robb's example) 
  3159. '123*û456'    QRAD  í   '246*û114' (simplification) 
  3160.  
  3161. Students would *kill* for this program, so don't tell 'em 
  3162. you have it.  -jkh- 
  3163. @@SIMPLEX2   SG 
  3164. (Comp.sys.hp48) 
  3165. Item: 2940 by kevin@rodin.wustl.edu [Kevin Ruland] 
  3166. Subj: Simplex v1.2 library 
  3167. Date: 04 Feb 1993 
  3168.  
  3169. ííííííííííííííííííííííííííííííííííííííííííííííííííííííííí 
  3170. Simplex Library v1.2                               2-4-93 
  3171. ííííííííííííííííííííííííííííííííííííííííííííííííííííííííí 
  3172.  
  3173. This library is used to solve linear programming problems 
  3174. using the 2 phase simplex algorithm. I find it very 
  3175. fast, it can solve a 8 variables by 5 constraints problem 
  3176. in less than 7 seconds performing 5 iterations on the 
  3177. tableau. This is over 50% better than the original 
  3178. userRPL/sysRPL version. 
  3179.  
  3180. The problem this program is intended to solve is of the 
  3181. form, 
  3182.  
  3183.      min    c.x 
  3184.      st     A.x =  b    (* b must be greater than zero *) 
  3185.               x >= 0 
  3186.  
  3187. The way the problem is entered is as a matrix of the 
  3188. following form, 
  3189.  
  3190.              [ c |  0 ] 
  3191.              [---+----] 
  3192.              [ A |  b ] 
  3193.  
  3194. For examples to solve the following problem 
  3195.  
  3196.            max x1 + 2 x2 + x3 
  3197.            st 
  3198.                x1 + x2      <= 3 
  3199.                x1 - x2 + x3 <= 3 
  3200.                     x2 + x3 <= 3 
  3201.                x1 + x2 + x3 >= 3 
  3202.                     x2      <= 2 
  3203.                x1, x2, x3 >=0 
  3204.  
  3205. We convert it to the standard form 
  3206.  
  3207.            min - x1 - 2 x2 - x3 
  3208.            st 
  3209.                x1 + x2      + x4                     = 3 
  3210.                x1 - x2 + x3      + x5                = 3 
  3211.                     x2 + x3           + x6           = 3 
  3212.                x1 + x2 + x3                - x7      = 3 
  3213.                     x2                          + x8 = 2 
  3214.                x1, x2, x3 >= 0 
  3215.  
  3216. And write it as a matrix to enter it in the program. 
  3217.  
  3218.           [[ -1 -2 -1 0 0 0  0 0 0 ] 
  3219.            [  1  1  0 1 0 0  0 0 3 ] 
  3220.            [  1 -1  1 0 1 0  0 0 3 ] 
  3221.            [  0  1  1 0 0 1  0 0 3 ] 
  3222.            [  1  1  1 0 0 0 -1 0 3 ] 
  3223.            [  0  1  0 0 0 0  0 1 2 ]] 
  3224.  
  3225. To solve the problem right away, just enter the matrix, 
  3226. press the [INIT] key which initializes the variable 
  3227. 'LPdat' in the current directory. Then press the [SOLVE] 
  3228. key which iterates and gives the solution in three parts 
  3229. as follows, 
  3230.  
  3231.            3:  :\Gl: [ -1 0 -1 0 0 ] 
  3232.            2:  :Z: -6 
  3233.            1:  :X: [ 2 .999999999998 2 0 0 0 2 1 ] 
  3234.  
  3235. Where x is the actual point that minimizes the problem, 
  3236. the \Gl (lambda) is the solution to the dual problem or 
  3237. shadow prices of each of the constraints, and Z is the 
  3238. objective function value at the point found to be the 
  3239. minimum. 
  3240.  
  3241. This is the end of the quick start procedure to solve 
  3242. Linear Programs (LP) with my program. Now lets go to 
  3243. some details... 
  3244.  
  3245. The solution of an LP can be classified into, 
  3246.  
  3247.      infeasible, when there is no point satisfying the 
  3248.                  set of constraints 
  3249.  
  3250.      unbounded, when the set of constraints can not 
  3251.                 restrict the decrease of the objective 
  3252.                 function (c.x) 
  3253.  
  3254.      feasible & bounded, when there is a solution to the 
  3255.                          set of constraints which 
  3256.                          minimizes the objective function 
  3257.                          value. 
  3258.  
  3259. The problem can handle all three cases, giving the 
  3260. solution when it is feasible and bounded, providing a ray 
  3261. (which is a vector through which you can infinitely 
  3262. decrease the objective function while remaining in the 
  3263. feasible region) when the solution is unbounded, or 
  3264. flagging that there is no feasible solution. 
  3265.  
  3266. To achieve the different solutions, the program goes 
  3267. through the two phase simplex method automatically (you 
  3268. don't have to include artificial variables). Phase 1 is 
  3269. used to derive a starting basic feasible solution by 
  3270. introducing a set of artificial variables with the 
  3271. objective of minimizing its sum; when this is achieved, 
  3272. the set of artificial variables is removed and Phase 2 
  3273. starts with the original objective function. (Refer to 
  3274. any LP book for more details into the 2 phase simplex 
  3275. method.)  One important thing to notice, is that the 
  3276. columns corresponding to the artificial variables, 
  3277. although not taken into account on phase 2, are not 
  3278. removed from the problem because it is sometimes useful 
  3279. to have these columns at the end of the problem in order 
  3280. to perform sensitivity analysis. 
  3281.  
  3282. The basic algorithm that I used to solve the problem is a 
  3283. pseudo revised simplex method, where all that is 
  3284. maintained is the inverse of the base, the set of basic 
  3285. and non basic variables, and the rest of the data 
  3286. provided at the initialization process. I think this is 
  3287. the most efficient procedure in terms of time because it 
  3288. requires less computations... 
  3289.  
  3290. Here's a brief explanation of what the library's commands 
  3291. do. 
  3292.  
  3293.   [INIT]  Initializes the set of variables that are 
  3294.           needed by the program. 
  3295.   [TABL]  Extract the current tableau from the problem. 
  3296.   [SOLU]  Extracts the solution from the current tableau. 
  3297.   [SRAY]  Extracts a ray from an unbounded LP. 
  3298.   [TRACE] Performs one iteration at a time, it is 
  3299.           equivalent to solve, but you can take a look at 
  3300.           the partial tableaus that are generated by the 
  3301.           procedure. 
  3302.   [SOLVE] Gives the answer to the LP if it exists. 
  3303.   [SLACK] ( 1: array í  1: array) Adds a slack variable 
  3304.           to each constraint ( 2: array 1: list í  1: 
  3305.           array) Adds a slack variable to each constraint 
  3306.           in list. Constraints are numbered from 1 
  3307.           (meaning the second row of the matrix is the 
  3308.           first constraint). 
  3309.   [NEWV]  ( 3: problem (m+1xn+1 array) 2: consts of new 
  3310.           vars (1xp array) 
  3311.             1: constraint coeffs of new vars (pxm array) 
  3312.            í  1: new problem (m+1xn+p+1 array) ) 
  3313.           Adds variables to a problem. 
  3314.   [ABOUT] Minimalist "about" screen. 
  3315. @@NUM        SG 
  3316. NUM, a toolkit for heavy math.  Menu keys: 
  3317.  
  3318.      [SOLV]  Solving Equation 
  3319.      [SYST]  Solving System of Equations 
  3320.      [INTG]  Integrating Function 
  3321.      [DIFF]  Computing Differential Equation 
  3322.      [ASIM]  Continual Analogical Simulation 
  3323.      [IPOL]  Interpolation 
  3324.      [CFIT]  Curve Fitting 
  3325.      [TRANS] Transforming Coordinates 
  3326.      [REVä]  Reversing äDAT Matrix 
  3327.      [ORDä]  Ordering äDAT Matrix 
  3328.      [DRWä]  Plotting äDAT Matrix (autoscaled) 
  3329.      [SCLä]  Plotting äDAT Matrix (scale plot) 
  3330.      [LINä]  Connecting scattered Points by Lines 
  3331.  
  3332. The actual documentation file is over 55K, much too large 
  3333. to fit this DOC viewer.  Go into the MATH subdirectory on 
  3334. this disk, copy NUM.EXE onto your PC's hard disk, and run 
  3335. it there.  It'll create NUM.DOC which you can then view 
  3336. with LIST.COM; I recommend printing a hard copy. 
  3337.